From 40c4d95a2b8aaf8663c2eb94d44281f5a6bf1346 Mon Sep 17 00:00:00 2001 From: Marco Cawthorne Date: Thu, 4 May 2023 08:23:24 -0700 Subject: [PATCH] entityDef: Fix 'spawnclass' not working when referencing other entitydefs --- src/server/entityDef.qc | 44 ++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/src/server/entityDef.qc b/src/server/entityDef.qc index 62059a8b..4272f245 100644 --- a/src/server/entityDef.qc +++ b/src/server/entityDef.qc @@ -179,26 +179,38 @@ EntityDef_PrepareEntity(entity target, int id) int spawnWords = 0i; NSEntity targetEnt = (NSEntity)target; entity oldSelf = self; + bool isEntDefBased = false; - /* first we spawn it as the base spawnclass */ - if (!isfunction(g_entDefTable[id].spawnClass)) { - spawnClass = strcat("spawnfunc_", g_entDefTable[id].spawnClass); - } else { - spawnClass = g_entDefTable[id].spawnClass; + /* check if the spawnclass is an entityDef */ + for (int i = 0i; i < g_entDefCount; i++) { + if (g_entDefTable[id].spawnClass == g_entDefTable[i].entClass) { + EntityDef_PrepareEntity(self, i); + isEntDefBased = true; + break; + } } - /* init */ - self = target; - callfunction(spawnClass); - self = oldSelf; + if (isEntDefBased == false) { + /* first we spawn it as the base spawnclass */ + if (!isfunction(g_entDefTable[id].spawnClass)) { + spawnClass = strcat("spawnfunc_", g_entDefTable[id].spawnClass); + } else { + spawnClass = g_entDefTable[id].spawnClass; + } - /* first load all keys we inherit from the 'inherited' class */ - 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)); + /* init */ + self = target; + callfunction(spawnClass); + self = oldSelf; + + /* first load all keys we inherit from the 'inherited' class */ + 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)); + } } } }