diff --git a/src/entities/cannons/cannon.c b/src/entities/cannons/cannon.c index 54a6d19..72f374a 100644 --- a/src/entities/cannons/cannon.c +++ b/src/entities/cannons/cannon.c @@ -27,7 +27,7 @@ static void animate(void); static int canFire(Entity *target); static void preFire(void); -void initCannon(void) +Entity *initCannon(void) { Unit *u; @@ -56,6 +56,8 @@ void initCannon(void) u->walk = walk; u->die = die; u->canFire = canFire; + + return (Entity*)u; } static void applyDamage(int damage) diff --git a/src/entities/entityFactory.c b/src/entities/entityFactory.c index 0dd34c7..4e3236d 100644 --- a/src/entities/entityFactory.c +++ b/src/entities/entityFactory.c @@ -49,6 +49,7 @@ void initEntityFactory(void) addEntityDef("SpreadGunEyeDroid", initSpreadGunDroid); addEntityDef("PlasmaEyeDroid", initPlasmaDroid); addEntityDef("PlasmaBlob", initPlasmaBlob); + addEntityDef("Cannon", initCannon); addEntityDef("Bob", initBob); addEntityDef("MIA", initMIA); @@ -83,6 +84,8 @@ void initEntityFactory(void) addEntityDef("CardReader", initCardReader); addEntityDef("LaserTrap", initLaserTrap); addEntityDef("HorizontalLaserTrap", initHorizontalLaserTrap); + addEntityDef("Exit", initExit); + addEntityDef("Destructable", initDestructable); } Entity *createEntity(char *name) diff --git a/src/entities/entityFactory.h b/src/entities/entityFactory.h index da535b8..9ce7659 100644 --- a/src/entities/entityFactory.h +++ b/src/entities/entityFactory.h @@ -65,5 +65,8 @@ extern Entity *initSpreadGunDroid(void); extern Entity *initPlasmaDroid(void); extern Entity *initPlasmaBlob(void); extern Entity *initTeeka(void); +extern Entity *initExit(void); +extern Entity *initDestructable(void); +extern Entity *initCannon(void); extern World world; diff --git a/src/entities/misc/destructable.c b/src/entities/misc/destructable.c index 698d6be..3000c8b 100644 --- a/src/entities/misc/destructable.c +++ b/src/entities/misc/destructable.c @@ -22,14 +22,14 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. static void applyDamage(int amount); static void action(void); +static void load(cJSON *root); +static void save(cJSON *root); -void initDestructable(Entity *e) +Entity *initDestructable(void) { Structure *s; - initEntity(e); - - s = (Structure*)e; + s = createStructure(); s->type = ET_DESTRUCTABLE; @@ -45,6 +45,10 @@ void initDestructable(Entity *e) s->applyDamage = applyDamage; s->action = action; + s->load = load; + s->save = save; + + return (Entity*)s; } static void applyDamage(int amount) @@ -92,3 +96,31 @@ static void action(void) } } } + +static void load(cJSON *root) +{ + Structure *s; + + s = (Structure*)self; + + s->health = cJSON_GetObjectItem(root, "health")->valueint; + s->healthMax = cJSON_GetObjectItem(root, "healthMax")->valueint; + STRNCPY(s->spriteName, cJSON_GetObjectItem(root, "spriteName")->valuestring, MAX_NAME_LENGTH); + + if (cJSON_GetObjectItem(root, "targetNames")) + { + STRNCPY(s->targetNames, cJSON_GetObjectItem(root, "targetNames")->valuestring, MAX_DESCRIPTION_LENGTH); + } +} + +static void save(cJSON *root) +{ + Structure *s; + + s = (Structure*)self; + + cJSON_AddNumberToObject(root, "health", s->health); + cJSON_AddNumberToObject(root, "healthMax", s->healthMax); + cJSON_AddStringToObject(root, "spriteName", s->spriteName); + cJSON_AddStringToObject(root, "targetNames", s->targetNames); +} diff --git a/src/entities/misc/destructable.h b/src/entities/misc/destructable.h index a98970b..05c31d5 100644 --- a/src/entities/misc/destructable.h +++ b/src/entities/misc/destructable.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 activateEntities(char *names, int activate); extern void dropCarriedItem(void); @@ -28,5 +29,6 @@ extern void addScorchDecal(int x, int y); extern Sprite *getSprite(char *name); extern void updateObjective(char *targetName); extern void initEntity(Entity *e); +extern Structure *createStructure(void); extern Entity *self; diff --git a/src/entities/structures/exit.c b/src/entities/structures/exit.c index 46dcd60..536a9fb 100644 --- a/src/entities/structures/exit.c +++ b/src/entities/structures/exit.c @@ -23,6 +23,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. static void tick(void); static void action(void); static void touch(Entity *other); +static void load(cJSON *root); +static void save(cJSON *root); Entity *initExit(void) { @@ -54,6 +56,8 @@ Entity *initExit(void) s->tick = tick; s->action = action; s->touch = touch; + s->load = load; + s->save = save; return (Entity*)s; } @@ -125,3 +129,21 @@ static void touch(Entity *other) s->bobTouching = 2; } } + +static void load(cJSON *root) +{ + Structure *s; + + s = (Structure*)self; + + s->active = cJSON_GetObjectItem(root, "active")->valueint; +} + +static void save(cJSON *root) +{ + Structure *s; + + s = (Structure*)self; + + cJSON_AddNumberToObject(root, "active", s->active); +} diff --git a/src/entities/structures/exit.h b/src/entities/structures/exit.h index 4a06e85..b2afec4 100644 --- a/src/entities/structures/exit.h +++ b/src/entities/structures/exit.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 Sprite *getSprite(char *name); extern void updateObjective(char *targetName); diff --git a/src/world/entities.c b/src/world/entities.c index a335fab..9c9f7af 100644 --- a/src/world/entities.c +++ b/src/world/entities.c @@ -397,14 +397,14 @@ static void moveEntity(void) haltAtEdge(); } - // Deal with x movement + /* Deal with x movement */ position.x = self->x; position.y = self->y; position.x += self->dx; moveToOthers(self->dx, 0, &position); moveToMap(self->dx, 0, &position); - // Deal with Y movement + /* Deal with Y movement */ position.y += self->dy; moveToOthers(0, self->dy, &position); moveToMap(0, self->dy, &position);