From db9cddb7e86f87f9729fcfc7ed910971f111a239 Mon Sep 17 00:00:00 2001 From: Steve Date: Sat, 24 Feb 2018 16:00:48 +0000 Subject: [PATCH] Load / save functions for weapon pickups. --- src/entities/items/weaponPickup.c | 19 +++++++++++++++++++ src/entities/items/weaponPickup.h | 2 ++ src/system/lookup.c | 3 +++ 3 files changed, 24 insertions(+) diff --git a/src/entities/items/weaponPickup.c b/src/entities/items/weaponPickup.c index eba2733..e4345f0 100644 --- a/src/entities/items/weaponPickup.c +++ b/src/entities/items/weaponPickup.c @@ -24,6 +24,8 @@ static void (*superTick)(void); static void init(void); static void tick(void); static void touch(Entity *other); +static void load(cJSON *root); +static void save(cJSON *root); Entity *initWeaponPickup(void) { @@ -38,6 +40,8 @@ Entity *initWeaponPickup(void) i->init = init; i->tick = tick; i->touch = touch; + i->load = load; + i->save = save; return (Entity*)i; } @@ -100,3 +104,18 @@ static void touch(Entity *other) game.stats[STAT_WEAPONS_PICKED_UP]++; } } + +static void load(cJSON *root) +{ + Item *i; + + i = (Item*)self; + + i->weaponType = lookup(cJSON_GetObjectItem(root, "weaponType")->valuestring); + i->provided = cJSON_GetObjectItem(root, "provided")->valueint; +} + +static void save(cJSON *root) +{ + /* boss missions, only - not going to worry about saving these */ +} diff --git a/src/entities/items/weaponPickup.h b/src/entities/items/weaponPickup.h index 5848231..989a49d 100644 --- a/src/entities/items/weaponPickup.h +++ b/src/entities/items/weaponPickup.h @@ -19,6 +19,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "../../common.h" +#include "../../json/cJSON.h" extern void playSound(int snd, int ch); extern void setGameplayMessage(int type, char *format, ...); @@ -27,6 +28,7 @@ extern void pickupItem(void); extern int touchedPlayer(Entity *e); extern const char *getWeaponName(int i); extern Entity *initConsumable(void); +extern int lookup(char *name); extern Entity *self; extern Game game; diff --git a/src/system/lookup.c b/src/system/lookup.c index 2a0e508..4424451 100644 --- a/src/system/lookup.c +++ b/src/system/lookup.c @@ -39,6 +39,9 @@ void initLookups(void) addLookup("DOOR_OPEN", DOOR_OPEN); addLookup("DOOR_CLOSED", DOOR_CLOSED); + addLookup("WPN_PLASMA", WPN_PLASMA); + addLookup("WPN_SPREAD", WPN_SPREAD); + addLookup("CONTROL_LEFT", CONTROL_LEFT); addLookup("CONTROL_RIGHT", CONTROL_RIGHT); addLookup("CONTROL_UP", CONTROL_UP);