entityDef: Fix 'spawnclass' not working when referencing other entitydefs

This commit is contained in:
Marco Cawthorne 2023-05-04 08:23:24 -07:00
parent 49d44bb21f
commit 40c4d95a2b
Signed by: eukara
GPG Key ID: CE2032F0A2882A22
1 changed files with 28 additions and 16 deletions

View File

@ -179,26 +179,38 @@ EntityDef_PrepareEntity(entity target, int id)
int spawnWords = 0i; int spawnWords = 0i;
NSEntity targetEnt = (NSEntity)target; NSEntity targetEnt = (NSEntity)target;
entity oldSelf = self; entity oldSelf = self;
bool isEntDefBased = false;
/* first we spawn it as the base spawnclass */ /* check if the spawnclass is an entityDef */
if (!isfunction(g_entDefTable[id].spawnClass)) { for (int i = 0i; i < g_entDefCount; i++) {
spawnClass = strcat("spawnfunc_", g_entDefTable[id].spawnClass); if (g_entDefTable[id].spawnClass == g_entDefTable[i].entClass) {
} else { EntityDef_PrepareEntity(self, i);
spawnClass = g_entDefTable[id].spawnClass; isEntDefBased = true;
break;
}
} }
/* init */ if (isEntDefBased == false) {
self = target; /* first we spawn it as the base spawnclass */
callfunction(spawnClass); if (!isfunction(g_entDefTable[id].spawnClass)) {
self = oldSelf; spawnClass = strcat("spawnfunc_", g_entDefTable[id].spawnClass);
} else {
spawnClass = g_entDefTable[id].spawnClass;
}
/* first load all keys we inherit from the 'inherited' class */ /* init */
for (int x = 0; x < g_entDefCount; x++) { self = target;
/* found the thing we're supposed to inherit */ callfunction(spawnClass);
if (g_entDefTable[x].entClass == g_entDefTable[id].inheritKeys) { self = oldSelf;
spawnWords = tokenize_console(g_entDefTable[x].spawnData);
for (int i = 0; i < spawnWords; i+= 2) { /* first load all keys we inherit from the 'inherited' class */
targetEnt.SpawnKey(argv(i), argv(i+1)); for (int x = 0; x < g_entDefCount; x++) {
/* found the thing we're supposed to inherit */
if (g_entDefTable[x].entClass == g_entDefTable[id].inheritKeys) {
spawnWords = tokenize_console(g_entDefTable[x].spawnData);
for (int i = 0; i < spawnWords; i+= 2) {
targetEnt.SpawnKey(argv(i), argv(i+1));
}
} }
} }
} }