View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update | 
|---|---|---|---|---|---|
| 0002385 | FSSCP | tables | public | 2011-01-24 05:00 | 2011-02-04 17:19 | 
| Reporter | FUBAR-BDHR | Assigned To | The_E | ||
| Priority | normal | Severity | feature | Reproducibility | always | 
| Status | resolved | Resolution | fixed | ||
| Product Version | 3.6.13 | ||||
| Fixed in Version | 3.6.13 | ||||
| Summary | 0002385: Animation code should be using subobject names not numbers | ||||
| Description | This is kind of a feature and a bug so putting it here.  The issue with using subobject numbers for the animation code is that they change.  Something as simple as opening an older versions of a model in a newer version of pcs2 can result in different subobject numbers.  Max constantly rearranges them. Even saving and reopening a model will often result in different subobject numbers on export. Of course we would need to keep the existing subobject number option for backward compatibility. Adding a +sub_name option would probably be the best. It would also allow for better error checking in the future as a deleted object would no longer be found. | ||||
| Tags | No tags attached. | ||||
| 
 2011-01-24 17:04 
 |  2385.patch (2,267 bytes)   
 Index: model/modelanim.h
===================================================================
--- model/modelanim.h	(revision 6969)
+++ model/modelanim.h	(working copy)
@@ -66,6 +66,8 @@
 	int loop_sound;
 	int end_sound;
 	float snd_rad;
+
+	char sub_name[NAME_LENGTH];
 };
 
 /*
Index: ship/ship.cpp
===================================================================
--- ship/ship.cpp	(revision 6969)
+++ ship/ship.cpp	(working copy)
@@ -375,6 +375,8 @@
 
 bool warning_too_many_ship_classes = false;
 
+int ship_get_subobj_model_num(ship_info* sip, char* subobj_name);
+
 // set the ship_obj struct fields to default values
 void ship_obj_list_reset_slot(int index)
 {
@@ -3177,7 +3179,13 @@
 						current_trigger->subtype = ANIMATION_SUBTYPE_ALL;
 					}
 
+					if(optional_string("+sub_name:")) {
+						stuff_string(current_trigger->sub_name, F_NAME, NAME_LENGTH);
+					} else {
+						strcpy_s(current_trigger->sub_name, "<none>");
+					}
 
+
 					if(current_trigger->type == TRIGGER_TYPE_INITIAL){
 						//the only thing initial animation type needs is the angle, 
 						//so to save space lets just make everything optional in this case
@@ -3340,7 +3348,21 @@
 
 	strcpy_s(parse_error_text, "");
 
+	// Fix up animation code references
+	for (int i = 0; i < sip->n_subsystems; i++) {
+		for (int j = 0; j < sip->subsystems[i].n_triggers; j++) {
+			if (stricmp(sip->subsystems[i].triggers[j].sub_name, "<none>")) {
+				int idx = ship_get_subobj_model_num(sip, sip->subsystems[i].triggers[j].sub_name);
+				if (idx != -1) {
+					sip->subsystems[i].triggers[j].subtype = idx;
+				} else {
+					WarningEx(LOCATION, "Could not find subobject %s in ship class %s. Animation triggers will not work correctly.\n", sip->subsystems[i].triggers[j].sub_name, sip->name);
+				}
+			}
+		}
+	}
 
+
 	return rtn;	//0 for success
 }
 
@@ -16922,3 +16944,13 @@
 			Warning(LOCATION, "Unrecognized weapon '%s' found when setting weapon targeting priorities.\n", tempname);
 	}
 }
+
+int ship_get_subobj_model_num(ship_info* sip, char* subobj_name) 
+{
+	for (int i = 0; i < sip->n_subsystems; i++) {
+		if (!stricmp(sip->subsystems[i].name, subobj_name))
+			return sip->subsystems[i].subobj_num;
+	}
+
+	return -1;
+}
\ No newline at end of file
 | 
|  | Proposed patch is attached. Adds "+sub_name" to the animation code, to be placed after or instead of "+sub_type". | 
|  | Doesn't seem to work.  I changed 5 turret doors to use +sub_name and while they do trigger to open they never stop rotating and never close.  Left the rest on +sub_type and they still work. Found and fixed one bug. Line 71 in that patch should be if (!stricmp(sip->subsystems[i].subobj_name, subobj_name)) Even with that it seems that sip->subsystems[i].subobj_num is not defined yet as every single one has a value of 0xcccccccc | 
|  | Yeah, I was sort of afraid of that. Second patch uploaded, this one moves the fixing of animation references into ship_set, during mission load (which is where model data is mated with tbl data. Didn't want to slow down the init process by having to load the model during startup....) | 
| 
 2011-01-25 18:11 
 |  2385-2.patch (2,377 bytes)   
 Index: model/modelanim.h
===================================================================
--- model/modelanim.h	(revision 6976)
+++ model/modelanim.h	(working copy)
@@ -66,6 +66,8 @@
 	int loop_sound;
 	int end_sound;
 	float snd_rad;
+
+	char sub_name[NAME_LENGTH];
 };
 
 /*
Index: ship/ship.cpp
===================================================================
--- ship/ship.cpp	(revision 6976)
+++ ship/ship.cpp	(working copy)
@@ -375,6 +375,8 @@
 
 bool warning_too_many_ship_classes = false;
 
+int ship_get_subobj_model_num(ship_info* sip, char* subobj_name);
+
 // set the ship_obj struct fields to default values
 void ship_obj_list_reset_slot(int index)
 {
@@ -3177,7 +3179,13 @@
 						current_trigger->subtype = ANIMATION_SUBTYPE_ALL;
 					}
 
+					if(optional_string("+sub_name:")) {
+						stuff_string(current_trigger->sub_name, F_NAME, NAME_LENGTH);
+					} else {
+						strcpy_s(current_trigger->sub_name, "<none>");
+					}
 
+
 					if(current_trigger->type == TRIGGER_TYPE_INITIAL){
 						//the only thing initial animation type needs is the angle, 
 						//so to save space lets just make everything optional in this case
@@ -3340,7 +3348,6 @@
 
 	strcpy_s(parse_error_text, "");
 
-
 	return rtn;	//0 for success
 }
 
@@ -5214,6 +5221,20 @@
 		ship_recalc_subsys_strength( shipp );
 	}
 
+	// Fix up animation code references
+	for (int i = 0; i < sinfo->n_subsystems; i++) {
+		for (int j = 0; j < sinfo->subsystems[i].n_triggers; j++) {
+			if (stricmp(sinfo->subsystems[i].triggers[j].sub_name, "<none>")) {
+				int idx = ship_get_subobj_model_num(sinfo, sinfo->subsystems[i].triggers[j].sub_name);
+				if (idx != -1) {
+					sinfo->subsystems[i].triggers[j].subtype = idx;
+				} else {
+					WarningEx(LOCATION, "Could not find subobject %s in ship class %s. Animation triggers will not work correctly.\n", sinfo->subsystems[i].triggers[j].sub_name, sinfo->name);
+				}
+			}
+		}
+	}
+
 	return 1;
 }
 
@@ -16922,3 +16943,13 @@
 			Warning(LOCATION, "Unrecognized weapon '%s' found when setting weapon targeting priorities.\n", tempname);
 	}
 }
+
+int ship_get_subobj_model_num(ship_info* sip, char* subobj_name) 
+{
+	for (int i = 0; i < sip->n_subsystems; i++) {
+		if (!stricmp(sip->subsystems[i].subobj_name, subobj_name))
+			return sip->subsystems[i].subobj_num;
+	}
+
+	return -1;
+}
\ No newline at end of file
 | 
|  | Looks good. | 
|  | Committed to trunk in revision 7000 | 
| Date Modified | Username | Field | Change | 
|---|---|---|---|
| 2011-01-24 05:00 | FUBAR-BDHR | New Issue | |
| 2011-01-24 17:04 | The_E | File Added: 2385.patch | |
| 2011-01-24 17:05 | The_E | Note Added: 0012611 | |
| 2011-01-25 05:18 | FUBAR-BDHR | Note Added: 0012612 | |
| 2011-01-25 06:02 | FUBAR-BDHR | Note Edited: 0012612 | |
| 2011-01-25 18:04 | The_E | Note Added: 0012613 | |
| 2011-01-25 18:11 | The_E | File Added: 2385-2.patch | |
| 2011-01-25 18:11 | The_E | Status | new => assigned | 
| 2011-01-25 18:11 | The_E | Assigned To | => The_E | 
| 2011-01-25 23:50 | FUBAR-BDHR | Note Added: 0012614 | |
| 2011-02-04 17:19 | The_E | Note Added: 0012623 | |
| 2011-02-04 17:19 | The_E | Status | assigned => resolved | 
| 2011-02-04 17:19 | The_E | Fixed in Version | => 3.6.13 | 
| 2011-02-04 17:19 | The_E | Resolution | open => fixed | 
