From 77b35148ecc69331fe1842fbfc2bc2730e387a12 Mon Sep 17 00:00:00 2001 From: Julian Date: Tue, 17 Mar 2020 13:40:09 -0300 Subject: [PATCH] Add spawnflags and keyvalue support (untested). --- src/dlls/dllapi.cpp | 9 ++++++++- src/dlls/monster_config.cpp | 38 +++++++++++++++++++++++++++++++------ src/dlls/monster_plugin.h | 7 +++++++ 3 files changed, 47 insertions(+), 7 deletions(-) diff --git a/src/dlls/dllapi.cpp b/src/dlls/dllapi.cpp index 0f0220b..73432e2 100644 --- a/src/dlls/dllapi.cpp +++ b/src/dlls/dllapi.cpp @@ -926,7 +926,14 @@ int mmDispatchSpawn( edict_t *pent ) if (monsters[index].pMonster != NULL) delete monsters[index].pMonster; } - + + // free any allocated keyvalue memory + for (index = 0; index < monster_spawn_count; index++) + { + if (monster_spawnpoint[index].keyvalue) + free(monster_spawnpoint[index].keyvalue); + } + // do level initialization stuff here... for (index = 0; monster_types[index].name[0]; index++) diff --git a/src/dlls/monster_config.cpp b/src/dlls/monster_config.cpp index 86d05f5..102bb82 100644 --- a/src/dlls/monster_config.cpp +++ b/src/dlls/monster_config.cpp @@ -62,11 +62,6 @@ bool get_input(FILE *fp, char *input) return FALSE; // no input found } -struct pKVD -{ - char key[33]; - char value[33]; -}; void scan_monster_cfg(FILE *fp) { // Let's make a full rework of this. -Giegue @@ -162,10 +157,16 @@ void scan_monster_cfg(FILE *fp) if (!badent) { + // Make room for entity-specific keyvalues. + if (monster) + { + // The line is a little too long, no? + monster_spawnpoint[monster_spawn_count].keyvalue = (pKVD*)calloc(32, sizeof(*monster_spawnpoint[monster_spawn_count].keyvalue)); + } + // Done. Let's process the keyvalues. for (int i = 0; i < (kvd_index-1); i++) { - // Any unknown keyvalue is ignored. // Any duplicate keyvalue is overwritten. if (strcmp(data[i].key, "origin") == 0) @@ -225,6 +226,31 @@ void scan_monster_cfg(FILE *fp) monster_spawnpoint[monster_spawn_count].angles[2] = z; } } + else if (strcmp(data[i].key, "spawnflags") == 0) + { + if (monster) + { + if (sscanf(data[i].value, "%i", &x) != 1) + { + LOG_MESSAGE(PLID, "ERROR: invalid spawnflags: %s", input); // print conflictive line + + // default to 30 seconds + LOG_MESSAGE(PLID, "ERROR: entity spawnflags will be set to none (0)"); + x = 0; + } + monster_spawnpoint[monster_spawn_count].spawnflags = x; + } + } + else + { + // We do not know this keyvalue, but an specific entity might use it. + // Save it for later + if (monster) + { + strcpy(data[i].key, monster_spawnpoint[monster_spawn_count].keyvalue[i].key); + strcpy(data[i].value, monster_spawnpoint[monster_spawn_count].keyvalue[i].value); + } + } } if (monster) diff --git a/src/dlls/monster_plugin.h b/src/dlls/monster_plugin.h index 2d2a5f1..71c8bf9 100644 --- a/src/dlls/monster_plugin.h +++ b/src/dlls/monster_plugin.h @@ -5,6 +5,11 @@ #ifndef MONSTER_PLUGIN_H #define MONSTER_PLUGIN_H +typedef struct pKVD +{ + char key[33]; + char value[33]; +}; typedef struct { @@ -33,6 +38,8 @@ typedef struct { Vector angles; float delay; unsigned char monster; + int spawnflags; + pKVD *keyvalue; float respawn_time; bool need_to_respawn; } monster_spawnpoint_t;