From 917753aefec8d081179a0afe4681d7670182d672 Mon Sep 17 00:00:00 2001 From: Steve Date: Tue, 30 Jan 2018 08:29:09 +0000 Subject: [PATCH] Loading some entities. --- common.mk | 5 +- src/entities/blobs/mia.c | 6 ++- src/entities/blobs/mia.h | 1 + src/entities/entityFactory.c | 61 +++++++++++++++++++++--- src/entities/entityFactory.h | 21 ++++++++ src/entities/evilBlobs/pistolBlob.c | 10 +++- src/entities/evilBlobs/pistolBlob.h | 25 ++++++++++ src/entities/eyeDroids/eyeDroid.c | 34 +++++++------ src/entities/eyeDroids/eyeDroid.h | 45 +++++++++++++++++ src/entities/eyeDroids/pistolDroid.c | 12 ++++- src/entities/eyeDroids/pistolDroid.h | 25 ++++++++++ src/entities/items/cell.c | 8 ++-- src/entities/items/cell.h | 2 +- src/entities/items/heart.c | 8 ++-- src/entities/items/heart.h | 2 +- src/entities/items/item.c | 16 +++++-- src/entities/items/key.c | 24 +++++----- src/entities/items/key.h | 2 +- src/entities/items/keycard.c | 40 ++++++++-------- src/entities/items/keycard.h | 2 +- src/entities/misc/infoPoint.c | 8 ++-- src/entities/misc/infoPoint.h | 2 +- src/entities/structures/door.c | 34 ++++++------- src/entities/structures/door.h | 1 + src/entities/structures/exit.c | 4 +- src/entities/structures/horizontalDoor.c | 42 +++++++++++----- src/entities/structures/horizontalDoor.h | 1 + src/entities/structures/lift.c | 8 ++-- src/entities/structures/lift.h | 2 +- src/entities/structures/powerPoint.c | 8 ++-- src/entities/structures/powerPoint.h | 2 +- src/entities/structures/powerPool.c | 8 ++-- src/entities/structures/powerPool.h | 2 +- src/entities/structures/pressurePlate.c | 8 ++-- src/entities/structures/pressurePlate.h | 2 +- src/entities/structures/pushBlock.c | 8 ++-- src/entities/structures/pushBlock.h | 2 +- src/entities/structures/structures.c | 2 + src/entities/structures/structures.h | 2 +- src/entities/structures/teleporter.c | 30 +++++++----- src/entities/structures/teleporter.h | 2 +- src/structs.h | 1 - src/test/atlasTest.c | 2 +- src/world/effects.c | 5 ++ src/world/particles.h | 1 - 45 files changed, 383 insertions(+), 153 deletions(-) create mode 100644 src/entities/evilBlobs/pistolBlob.h create mode 100644 src/entities/eyeDroids/eyeDroid.h create mode 100644 src/entities/eyeDroids/pistolDroid.h diff --git a/common.mk b/common.mk index b2166ce..d41d001 100644 --- a/common.mk +++ b/common.mk @@ -10,6 +10,7 @@ SEARCHPATH += src/entities/boss SEARCHPATH += src/entities/cannons SEARCHPATH += src/entities/decoration SEARCHPATH += src/entities/evilBlobs +SEARCHPATH += src/entities/eyeDroids SEARCHPATH += src/entities/items SEARCHPATH += src/entities/misc SEARCHPATH += src/entities/structures @@ -32,7 +33,7 @@ OBJS += atlas.o atlasTest.o aquaBlob.o OBJS += battery.o blaze.o bob.o boss.o blobBoss.o OBJS += camera.o cannon.o cardReader.o cell.o cherry.o combat.o consumable.o OBJS += debris.o destructable.o door.o draw.o -OBJS += effects.o entities.o entityFactory.o exit.o explosions.o eyeDroidCommander.o evilBlob.o +OBJS += effects.o entities.o entityFactory.o exit.o explosions.o eyeDroid.o eyeDroidCommander.o evilBlob.o OBJS += fleshChunk.o frost.o OBJS += game.o grenade.o OBJS += heart.o horizontalDoor.o horizontalLaserTrap.o hub.o hud.o @@ -42,7 +43,7 @@ OBJS += key.o keycard.o OBJS += laser.o laserTrap.o lift.o lookup.o OBJS += main.o map.o maths.o mia.o missile.o OBJS += objectives.o -OBJS += particles.o player.o powerPoint.o powerPool.o pressurePlate.o pushBlock.o +OBJS += particles.o player.o pistolBlob.o pistolDroid.o powerPoint.o powerPool.o pressurePlate.o pushBlock.o OBJS += quadtree.o OBJS += sound.o sprites.o structures.o OBJS += tankCommander.o tankTrack.o teeka.o teleporter.o text.o textures.o title.o triggers.o diff --git a/src/entities/blobs/mia.c b/src/entities/blobs/mia.c index b1f36b8..ff4ac67 100644 --- a/src/entities/blobs/mia.c +++ b/src/entities/blobs/mia.c @@ -26,13 +26,15 @@ static void touch(Entity *other); static void preTeleport(void); static void teleport(void); -void initMIA(void) +Entity *initMIA(void) { MIA *m; m = malloc(sizeof(MIA)); memset(m, 0, sizeof(MIA)); + initEntity((Entity*)m); + m->type = ET_MIA; m->tx = m->ty = -1; @@ -53,6 +55,8 @@ void initMIA(void) m->touch = touch; m->isMissionTarget = 1; + + return (Entity*)m; } void reinitMIA(Entity *e) diff --git a/src/entities/blobs/mia.h b/src/entities/blobs/mia.h index 5f69302..1dfd640 100644 --- a/src/entities/blobs/mia.h +++ b/src/entities/blobs/mia.h @@ -28,6 +28,7 @@ extern void setGameplayMessage(int type, char *format, ...); extern void playSound(int snd, int ch); extern void updateObjective(char *targetName); extern void addRescuedMIA(char *name); +extern void initEntity(Entity *e); extern Entity *self; extern World world; diff --git a/src/entities/entityFactory.c b/src/entities/entityFactory.c index e0a24bb..ca69330 100644 --- a/src/entities/entityFactory.c +++ b/src/entities/entityFactory.c @@ -20,7 +20,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "entityFactory.h" -static void addEntityDef(char *name, int type, Entity *(*initFunc)(void)); +static void addEntityDef(char *name, Entity *(*initFunc)(void)); +static Entity *initGenericEvilBlob(void); +static Entity *initGenericEyeDroid(void); static EntityDef head; static EntityDef *tail; @@ -30,11 +32,33 @@ void initEntityFactory(void) memset(&head, 0, sizeof(EntityDef)); tail = &head; - addEntityDef("AquaBlob", ET_ENEMY, initAquaBlob); + addEntityDef("AquaBlob", initAquaBlob); + addEntityDef("PistolBlob", initPistolBlob); + addEntityDef("PistolEyeDroid", initPistolDroid); + addEntityDef("GenericEvilBlob", initGenericEvilBlob); + addEntityDef("GenericEyeDroid", initGenericEyeDroid); - addEntityDef("Bob", ET_BOB, initBob); + addEntityDef("Bob", initBob); + addEntityDef("MIA", initMIA); - addEntityDef("Exit", ET_EXIT, initExit); + addEntityDef("Item", initItem); + addEntityDef("BronzeKey", initBronzeKey); + addEntityDef("SilverKey", initSilverKey); + addEntityDef("GoldKey", initGoldKey); + + addEntityDef("Exit", initExit); + addEntityDef("PowerPool", initPowerPool); + addEntityDef("Teleporter", initTeleporter); + addEntityDef("PressurePlate", initPressurePlate); + addEntityDef("InfoPoint", initInfoPoint); + addEntityDef("PowerPoint", initPowerPoint); + addEntityDef("PushBlock", initPushBlock); + addEntityDef("Lift", initLift); + addEntityDef("Door", initDoor); + addEntityDef("BronzeDoor", initBronzeDoor); + addEntityDef("SilverDoor", initSilverDoor); + addEntityDef("GoldDoor", initGoldDoor); + addEntityDef("HorizontalDoor", initHorizontalDoor); } Entity *createEntity(char *name) @@ -55,7 +79,7 @@ Entity *createEntity(char *name) return NULL; } -static void addEntityDef(char *name, int type, Entity *(*initFunc)(void)) +static void addEntityDef(char *name, Entity *(*initFunc)(void)) { EntityDef *def; @@ -65,6 +89,31 @@ static void addEntityDef(char *name, int type, Entity *(*initFunc)(void)) tail = def; STRNCPY(def->name, name, MAX_NAME_LENGTH); - def->type = type; def->initFunc = initFunc; } + +static Entity *initGenericEvilBlob(void) +{ + int r; + char name[MAX_NAME_LENGTH]; + strcpy(name, ""); + + r = rand() % world.numEnemyTypes; + + sprintf(name, "%sBlob", world.enemyTypes[r]); + + return createEntity(name); +} + +static Entity *initGenericEyeDroid(void) +{ + int r; + char name[MAX_NAME_LENGTH]; + strcpy(name, ""); + + r = rand() % world.numEnemyTypes; + + sprintf(name, "%sEyeDroid", world.enemyTypes[r]); + + return createEntity(name); +} diff --git a/src/entities/entityFactory.h b/src/entities/entityFactory.h index 6fe3249..d2d62e7 100644 --- a/src/entities/entityFactory.h +++ b/src/entities/entityFactory.h @@ -21,5 +21,26 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../common.h" extern Entity *initAquaBlob(void); +extern Entity *initPistolBlob(void); +extern Entity *initPistolDroid(void); extern Entity *initBob(void); extern Entity *initExit(void); +extern Entity *initPowerPool(void); +extern Entity *initTeleporter(void); +extern Entity *initPressurePlate(void); +extern Entity *initInfoPoint(void); +extern Entity *initPowerPoint(void); +extern Entity *initPushBlock(void); +extern Entity *initLift(void); +extern Entity *initDoor(void); +extern Entity *initBronzeDoor(void); +extern Entity *initSilverDoor(void); +extern Entity *initGoldDoor(void); +extern Entity *initHorizontalDoor(void); +extern Entity *initMIA(void); +extern Entity *initItem(void); +extern Entity *initBronzeKey(void); +extern Entity *initSilverKey(void); +extern Entity *initGoldKey(void); + +extern World world; diff --git a/src/entities/evilBlobs/pistolBlob.c b/src/entities/evilBlobs/pistolBlob.c index f729822..186b92b 100644 --- a/src/entities/evilBlobs/pistolBlob.c +++ b/src/entities/evilBlobs/pistolBlob.c @@ -22,8 +22,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. static int canFire(Entity *target); -void initPistolBlob(Unit *u) +Entity *initPistolBlob(void) { + Unit *u; + + u = createUnit(); + initEvilBlob(u); u->sprite[FACING_LEFT] = getSprite("PistolBlobLeft"); @@ -35,9 +39,11 @@ void initPistolBlob(Unit *u) u->maxShotsToFire = 3; u->canFire = canFire; + + return (Entity*)u; } static int canFire(Entity *target) { - return true; + return 1; } diff --git a/src/entities/evilBlobs/pistolBlob.h b/src/entities/evilBlobs/pistolBlob.h new file mode 100644 index 0000000..de1b0d2 --- /dev/null +++ b/src/entities/evilBlobs/pistolBlob.h @@ -0,0 +1,25 @@ +/* +Copyright (C) 2018 Parallel Realities + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#include "../../common.h" + +extern Unit *createUnit(void); +extern void initEvilBlob(Unit *u); +extern Sprite *getSprite(char *name); diff --git a/src/entities/eyeDroids/eyeDroid.c b/src/entities/eyeDroids/eyeDroid.c index 039b297..c358216 100644 --- a/src/entities/eyeDroids/eyeDroid.c +++ b/src/entities/eyeDroids/eyeDroid.c @@ -20,20 +20,24 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "eyeDroid.h" +static void walk(void); +static void die(void); static void tick(void); -static void superTick(void); -static void touch(void); -static void superTouch(void); +static void touch(Entity *other); +static void (*superTick)(void); +static void (*superTouch)(Entity *other); -void initEyeDroid(void) +void initEyeDroid(Unit *u) { - u->flags |= FL_WEIGHTLESS | FL_HALT_AT_EDGE | FL_EXPLODES; + u->flags |= EF_WEIGHTLESS | EF_HALT_AT_EDGE | EF_EXPLODES; superTick = u->tick; superTouch = u->touch; + u->walk = walk; u->tick = tick; u->touch = touch; + u->die = die; } static void tick(void) @@ -57,7 +61,7 @@ static void touch(Entity *other) u = (Unit*)self; - superTouch(); + superTouch(other); if (u->alive == ALIVE_DYING && (other == NULL || other->isSolid)) { @@ -76,7 +80,9 @@ static void touch(Entity *other) addRandomItems((int) u->x, (int) u->y); - updateObjectives(); + updateObjective(u->name); + updateObjective("ENEMY"); + fireTriggers(u->name); if (u->isMissionTarget) { @@ -94,7 +100,7 @@ static void touch(Entity *other) static void unitDie(void) { - if (self->environment != Environment.AIR) + if (self->environment != ENV_AIR) { touch(NULL); } @@ -106,7 +112,7 @@ static void die(void) u = (Unit*)self; - u->dx = (fRand() - fRand()) * 3; + u->dx = (randF() - randF()) * 3; u->spriteTime = 0; u->spriteFrame = 0; @@ -187,7 +193,7 @@ static void lookForPlayer(void) u->thinkTime = rrnd(FPS / 2, FPS); - if (world.state != WS_IN_PROGRESS || game.cheatBlind) + if (world.state != WS_IN_PROGRESS || dev.cheatBlind) { patrol(); return; @@ -207,23 +213,23 @@ static void lookForPlayer(void) return; } - r = fRand(); + r = randF(); if (u->isMissionTarget) { - r = fRand() * 0.3; + r = randF() * 0.3; } if (r < 0.125) { chase(); u->shotsToFire = rrnd(1, u->maxShotsToFire); - u->action = preFire; + u->action = u->preFire; } else if (r < 0.25) { u->dx = 0; u->shotsToFire = rrnd(1, u->maxShotsToFire); - u->action = preFire; + u->action = u->preFire; } else if (r < 0.5) { diff --git a/src/entities/eyeDroids/eyeDroid.h b/src/entities/eyeDroids/eyeDroid.h new file mode 100644 index 0000000..3303a71 --- /dev/null +++ b/src/entities/eyeDroids/eyeDroid.h @@ -0,0 +1,45 @@ +/* +Copyright (C) 2018 Parallel Realities + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#include "../../common.h" + +extern void dropCarriedItem(void); +extern int getDistance(int x1, int y1, int x2, int y2); +extern double randF(void); +extern void throwFleshChunks(float x, float y, int amount); +extern void addRandomWeapon(float x, float y); +extern float limit(float i, float a, float b); +extern void playSound(int snd, int ch); +extern void addBloodDecal(int x, int y); +extern void updateObjective(char *targetName); +extern int enemyCanSeePlayer(Entity *e); +extern void addDefeatedTarget(char *name); +extern void fireTriggers(char *name); +extern void addRandomItems(float x, float y); +extern int rrnd(int low, int high); +extern void addExplosion(float x, float y, int radius, Entity *owner); +extern void throwDebris(float x, float y, int amount); +extern void addSmokeParticles(float x, float y); +extern void addScorchDecal(int x, int y); + +extern Dev dev; +extern Entity *self; +extern Game game; +extern World world; diff --git a/src/entities/eyeDroids/pistolDroid.c b/src/entities/eyeDroids/pistolDroid.c index 123e372..1b5332a 100644 --- a/src/entities/eyeDroids/pistolDroid.c +++ b/src/entities/eyeDroids/pistolDroid.c @@ -22,8 +22,14 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. static int canFire(Entity *target); -void initPistolDroid(Unit *u) +Entity *initPistolDroid(void) { + Unit *u; + + u = createUnit(); + + initEyeDroid(u); + u->sprite[FACING_LEFT] = getSprite("PistolDroidLeft"); u->sprite[FACING_RIGHT] = getSprite("PistolDroidRight"); u->sprite[FACING_DIE] = getSprite("PistolDroidDie"); @@ -33,9 +39,11 @@ void initPistolDroid(Unit *u) u->maxShotsToFire = 3; u->canFire = canFire; + + return (Entity*)u; } static int canFire(Entity *target) { - return true; + return 1; } diff --git a/src/entities/eyeDroids/pistolDroid.h b/src/entities/eyeDroids/pistolDroid.h new file mode 100644 index 0000000..ad19b31 --- /dev/null +++ b/src/entities/eyeDroids/pistolDroid.h @@ -0,0 +1,25 @@ +/* +Copyright (C) 2018 Parallel Realities + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#include "../../common.h" + +extern Unit *createUnit(void); +extern void initEyeDroid(Unit *u); +extern Sprite *getSprite(char *name); diff --git a/src/entities/items/cell.c b/src/entities/items/cell.c index 8c5d9d5..8e367cf 100644 --- a/src/entities/items/cell.c +++ b/src/entities/items/cell.c @@ -22,13 +22,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. static void touch(Entity *other); -void initCell(Entity *e) +Entity *initCell(void) { Item *i; - initItem(e); - - i = (Item*)self; + i = (Item*)createItem(); i->type = ET_HEART_CELL; @@ -42,6 +40,8 @@ void initCell(Entity *e) i->spriteTime = -1; i->touch = touch; + + return (Entity*)i; } static void touch(Entity *other) diff --git a/src/entities/items/cell.h b/src/entities/items/cell.h index 84029a4..1fb8a6d 100644 --- a/src/entities/items/cell.h +++ b/src/entities/items/cell.h @@ -20,7 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../../common.h" -extern void initItem(Entity *e); +extern Entity *createItem(void); extern Sprite *getSprite(char *name); extern void setGameplayMessage(int type, char *format, ...); extern void playSound(int snd, int ch); diff --git a/src/entities/items/heart.c b/src/entities/items/heart.c index 4223346..bbae850 100644 --- a/src/entities/items/heart.c +++ b/src/entities/items/heart.c @@ -23,13 +23,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. static void action(void); static void touch(Entity *other); -void initHeart(Entity *e) +Entity *initHeart(Entity *e) { Item *i; - initItem(e); - - i = (Item*)e; + i = (Item*)createItem(); i->type = ET_HEART_CELL; @@ -44,6 +42,8 @@ void initHeart(Entity *e) i->action = action; i->touch = touch; + + return (Entity*)i; } static void action(void) diff --git a/src/entities/items/heart.h b/src/entities/items/heart.h index 5418567..ccd0289 100644 --- a/src/entities/items/heart.h +++ b/src/entities/items/heart.h @@ -22,7 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. extern void playSound(int snd, int ch); extern void setGameplayMessage(int type, char *format, ...); -extern void initItem(Entity *e); +extern Entity *createItem(void); extern Sprite *getSprite(char *name); extern void updateObjective(char *targetName); extern int rrnd(int low, int high); diff --git a/src/entities/items/item.c b/src/entities/items/item.c index e48b519..db17e65 100644 --- a/src/entities/items/item.c +++ b/src/entities/items/item.c @@ -29,13 +29,16 @@ static void destructablePickupItem(Structure *s); static void enemyPickupItem(Unit *u); static void bobPickupItem(void); -void initItem(Entity *e) +Entity *createItem(void) { Item *i; - initEntity(e); + i = malloc(sizeof(Item)); + memset(i, 0, sizeof(Item)); + world.entityTail->next = (Entity*)i; + world.entityTail = (Entity*)i; - i = (Item*)e; + initEntity((Entity*)i); i->type = ET_ITEM; @@ -55,6 +58,13 @@ void initItem(Entity *e) i->changeEnvironment = changeEnvironment; i->reset = reset; i->die = die; + + return (Entity*)i; +} + +Entity *initItem(void) +{ + return createItem(); } static void reset(void) diff --git a/src/entities/items/key.c b/src/entities/items/key.c index 01c5d33..5c0c9ce 100644 --- a/src/entities/items/key.c +++ b/src/entities/items/key.c @@ -20,44 +20,44 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "key.h" -void initBronzeKey(Entity *e) +Entity *initBronzeKey(Entity *e) { Item *i; - initItem(e); - - i = (Item*)e; + i = (Item*)createItem(); i->type = ET_KEY; STRNCPY(i->name, "Bronze Key", MAX_NAME_LENGTH); STRNCPY(i->spriteName, "BronzeKey", MAX_NAME_LENGTH); + + return (Entity*)i; } -void initSilverKey(Entity *e) +Entity *initSilverKey(Entity *e) { Item *i; - initItem(e); - - i = (Item*)e; + i = (Item*)createItem(); i->type = ET_KEY; STRNCPY(i->name, "Silver Key", MAX_NAME_LENGTH); STRNCPY(i->spriteName, "SilverKey", MAX_NAME_LENGTH); + + return (Entity*)i; } -void initGoldKey(Entity *e) +Entity *initGoldKey(Entity *e) { Item *i; - initItem(e); - - i = (Item*)e; + i = (Item*)createItem(); i->type = ET_KEY; STRNCPY(i->name, "Gold Key", MAX_NAME_LENGTH); STRNCPY(i->spriteName, "GoldKey", MAX_NAME_LENGTH); + + return (Entity*)i; } diff --git a/src/entities/items/key.h b/src/entities/items/key.h index ffaf5f3..550e089 100644 --- a/src/entities/items/key.h +++ b/src/entities/items/key.h @@ -20,4 +20,4 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../../common.h" -extern void initItem(Entity *e); +extern Entity *createItem(void); diff --git a/src/entities/items/keycard.c b/src/entities/items/keycard.c index 081ad13..cc24091 100644 --- a/src/entities/items/keycard.c +++ b/src/entities/items/keycard.c @@ -23,69 +23,67 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. static void (*itemTouch)(Entity *other); static void touchWhiteKeycard(Entity *other); -void initRedKeycard(Entity *e) +Entity *initRedKeycard(void) { Item *i; - initItem(e); - - i = (Item*)e; + i = (Item*)createItem(); i->type = ET_KEY; STRNCPY(i->name, "Red Keycard", MAX_NAME_LENGTH); STRNCPY(i->spriteName, "RedKeycard", MAX_NAME_LENGTH); + + return (Entity*)i; } -void initBlueKeycard(Entity *e) +Entity *initBlueKeycard(void) { Item *i; - initItem(e); - - i = (Item*)e; + i = (Item*)createItem(); i->type = ET_KEY; STRNCPY(i->name, "Blue Keycard", MAX_NAME_LENGTH); STRNCPY(i->spriteName, "BlueKeycard", MAX_NAME_LENGTH); + + return (Entity*)i; } -void initGreenKeycard(Entity *e) +Entity *initGreenKeycard(void) { Item *i; - initItem(e); - - i = (Item*)e; + i = (Item*)createItem(); i->type = ET_KEY; STRNCPY(i->name, "Green Keycard", MAX_NAME_LENGTH); STRNCPY(i->spriteName, "GreenKeycard", MAX_NAME_LENGTH); + + return (Entity*)i; } -void initYellowKeycard(Entity *e) +Entity *initYellowKeycard(void) { Item *i; - initItem(e); - - i = (Item*)e; + i = (Item*)createItem(); i->type = ET_KEY; STRNCPY(i->name, "Yellow Keycard", MAX_NAME_LENGTH); STRNCPY(i->spriteName, "YellowKeycard", MAX_NAME_LENGTH); + + return (Entity*)i; } -void initWhiteKeycard(Entity *e) +Entity *initWhiteKeycard(void) { Item *i; - initItem(e); - - i = (Item*)e; + i = (Item*)createItem(); i->type = ET_KEY; @@ -95,6 +93,8 @@ void initWhiteKeycard(Entity *e) itemTouch = i->touch; i->touch = touchWhiteKeycard; + + return (Entity*)i; } static void touchWhiteKeycard(Entity *other) diff --git a/src/entities/items/keycard.h b/src/entities/items/keycard.h index 726e5fa..d210fef 100644 --- a/src/entities/items/keycard.h +++ b/src/entities/items/keycard.h @@ -20,7 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../../common.h" -extern void initItem(Entity *e); +extern Entity *createItem(void); extern void updateObjective(char *targetName); extern void teekaExitMission(void); diff --git a/src/entities/misc/infoPoint.c b/src/entities/misc/infoPoint.c index 9eca5d0..1757ca1 100644 --- a/src/entities/misc/infoPoint.c +++ b/src/entities/misc/infoPoint.c @@ -23,13 +23,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. static void tick(void); static void touch(Entity *other); -void initInfoPoint(Entity *e) +Entity *initInfoPoint(void) { Structure *s; - initEntity(e); - - s = (Structure*)e; + s = createStructure(); s->type = ET_INFO_POINT; @@ -43,6 +41,8 @@ void initInfoPoint(Entity *e) s->tick = tick; s->touch = touch; + + return (Entity*)s; } static void tick(void) diff --git a/src/entities/misc/infoPoint.h b/src/entities/misc/infoPoint.h index d3275b8..d7eda86 100644 --- a/src/entities/misc/infoPoint.h +++ b/src/entities/misc/infoPoint.h @@ -21,8 +21,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../../common.h" extern Sprite *getSprite(char *name); -extern void initEntity(Entity *e); extern void showInfoMessage(char *message); +extern Structure *createStructure(void); extern Entity *self; extern World world; diff --git a/src/entities/structures/door.c b/src/entities/structures/door.c index e639f1f..3461540 100644 --- a/src/entities/structures/door.c +++ b/src/entities/structures/door.c @@ -27,13 +27,11 @@ static int isClosed(void); static int isOpening(void); static int isClosing(void); -void initDoor(Entity *e) +Entity *initDoor(void) { Structure *s; - initEntity(e); - - s = (Structure*)e; + s = createStructure(); s->type = ET_DOOR; @@ -59,51 +57,53 @@ void initDoor(Entity *e) s->tick = tick; s->touch = touch; + + return (Entity*)s; } -void initBronzeDoor(Entity *e) +Entity *initBronzeDoor(void) { Structure *s; - initDoor(e); - - s = (Structure*)e; + s = (Structure*)initDoor(); STRNCPY(s->requiredItem, "Bronze Key", MAX_NAME_LENGTH); s->speed = 2; s->sprite[0] = s->sprite[1] = s->sprite[2] = getSprite("BronzeDoor"); + + return (Entity*)s; } -void initSilverDoor(Entity *e) +Entity *initSilverDoor(void) { Structure *s; - initDoor(e); - - s = (Structure*)e; + s = (Structure*)initDoor(); STRNCPY(s->requiredItem, "Silver Key", MAX_NAME_LENGTH); s->speed = 2; s->sprite[0] = s->sprite[1] = s->sprite[2] = getSprite("SilverDoor"); + + return (Entity*)s; } -void initGoldDoor(Entity *e) +Entity *initGoldDoor(void) { Structure *s; - initDoor(e); - - s = (Structure*)e; + s = (Structure*)initDoor(); STRNCPY(s->requiredItem, "Gold Key", MAX_NAME_LENGTH); s->speed = 2; - s->sprite[0] = s->sprite[1] = e->sprite[2] = getSprite("GoldDoor"); + s->sprite[0] = s->sprite[1] = s->sprite[2] = getSprite("GoldDoor"); + + return (Entity*)s; } static void tick(void) diff --git a/src/entities/structures/door.h b/src/entities/structures/door.h index 279ade5..82a6572 100644 --- a/src/entities/structures/door.h +++ b/src/entities/structures/door.h @@ -27,6 +27,7 @@ extern void getSlope(int x1, int y1, int x2, int y2, float *dx, float *dy); extern void setGameplayMessage(int type, char *format, ...); extern int hasItem(char *name); extern void removeItem(char *name); +extern Structure *createStructure(void); extern Entity *self; extern Dev dev; diff --git a/src/entities/structures/exit.c b/src/entities/structures/exit.c index e97a001..a10e310 100644 --- a/src/entities/structures/exit.c +++ b/src/entities/structures/exit.c @@ -25,7 +25,7 @@ static void action(void); static void touch(Entity *other); static SDL_Rect *getBounds(void); -void initExit(void) +Entity *initExit(void) { Structure *s; @@ -56,6 +56,8 @@ void initExit(void) s->action = action; s->touch = touch; s->getBounds = getBounds; + + return (Entity*)s; } static void tick(void) diff --git a/src/entities/structures/horizontalDoor.c b/src/entities/structures/horizontalDoor.c index f852931..5aa0b5f 100644 --- a/src/entities/structures/horizontalDoor.c +++ b/src/entities/structures/horizontalDoor.c @@ -20,32 +20,48 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "horizontalDoor.h" -void initHorizontalDoor(Entity *e) +Entity *initHorizontalDoor(void) { - initDoor(e); + Structure *s; - e->type = ET_DOOR; + s = createStructure(); - e->sprite[0] = e->sprite[1] = e->sprite[2] = getSprite("HorizonalDoor"); + s->type = ET_DOOR; + + s->sprite[0] = s->sprite[1] = s->sprite[2] = getSprite("HorizonalDoor"); + + return (Entity*)s; } -void initBronzeHorizontalDoor(Entity *e) +Entity *initBronzeHorizontalDoor(void) { - initHorizontalDoor(e); + Structure *s; - STRNCPY(((Structure*)e)->requiredItem, "Bronze Key", MAX_NAME_LENGTH); + s = (Structure*)initHorizontalDoor(); + + STRNCPY(s->requiredItem, "Bronze Key", MAX_NAME_LENGTH); + + return (Entity*)s; } -void initSilverHorizontalDoor(Entity *e) +Entity *initSilverHorizontalDoor(void) { - initHorizontalDoor(e); + Structure *s; - STRNCPY(((Structure*)e)->requiredItem, "Silver Key", MAX_NAME_LENGTH); + s = (Structure*)initHorizontalDoor(); + + STRNCPY(s->requiredItem, "Silver Key", MAX_NAME_LENGTH); + + return (Entity*)s; } -void initGoldHorizontalDoor(Entity *e) +Entity *initGoldHorizontalDoor(void) { - initHorizontalDoor(e); + Structure *s; - STRNCPY(((Structure*)e)->requiredItem, "Gold Key", MAX_NAME_LENGTH); + s = (Structure*)initHorizontalDoor(); + + STRNCPY(s->requiredItem, "Gold Key", MAX_NAME_LENGTH); + + return (Entity*)s; } diff --git a/src/entities/structures/horizontalDoor.h b/src/entities/structures/horizontalDoor.h index 6060478..580b448 100644 --- a/src/entities/structures/horizontalDoor.h +++ b/src/entities/structures/horizontalDoor.h @@ -22,3 +22,4 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. extern void initDoor(Entity *e); extern Sprite *getSprite(char *name); +extern Structure *createStructure(void); diff --git a/src/entities/structures/lift.c b/src/entities/structures/lift.c index d0e2186..ec93899 100644 --- a/src/entities/structures/lift.c +++ b/src/entities/structures/lift.c @@ -23,13 +23,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. static void action(void); static void activate(int active); -void initLift(Entity *e) +Entity *initLift(Entity *e) { Structure *s; - initEntity(e); - - s = (Structure*)e; + s = createStructure(); s->type = ET_LIFT; @@ -49,6 +47,8 @@ void initLift(Entity *e) s->action = action; s->activate = activate; + + return (Entity*)s; } static void action(void) diff --git a/src/entities/structures/lift.h b/src/entities/structures/lift.h index 0ea9b21..d2908d9 100644 --- a/src/entities/structures/lift.h +++ b/src/entities/structures/lift.h @@ -20,11 +20,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../../common.h" -extern void initEntity(Entity *e); extern Sprite *getSprite(char *name); extern void getSlope(int x1, int y1, int x2, int y2, float *dx, float *dy); extern void observeActivation(Entity *e); extern int isOnScreen(Entity *e); extern void setGameplayMessage(int type, char *format, ...); +extern Structure *createStructure(void); extern Entity *self; diff --git a/src/entities/structures/powerPoint.c b/src/entities/structures/powerPoint.c index 59ddf18..0435238 100644 --- a/src/entities/structures/powerPoint.c +++ b/src/entities/structures/powerPoint.c @@ -24,13 +24,11 @@ static void tick(void); static void action(void); static void touch(Entity *other); -void initPowerPoint(Entity *e) +Entity *initPowerPoint(void) { Structure *s; - initEntity(e); - - s = (Structure*)e; + s = createStructure(); s->type = ET_POWER_POINT; @@ -45,6 +43,8 @@ void initPowerPoint(Entity *e) s->tick = tick; s->action = action; s->touch = touch; + + return (Entity*)s; } static void tick(void) diff --git a/src/entities/structures/powerPoint.h b/src/entities/structures/powerPoint.h index db439b6..d67ce52 100644 --- a/src/entities/structures/powerPoint.h +++ b/src/entities/structures/powerPoint.h @@ -20,10 +20,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../../common.h" -extern void initEntity(Entity *e); extern Sprite *getSprite(char *name); extern void activateEntities(char *names, int activate); extern void setGameplayMessage(int type, char *format, ...); +extern Structure *createStructure(void); extern Dev dev; extern Entity *self; diff --git a/src/entities/structures/powerPool.c b/src/entities/structures/powerPool.c index a80c9ff..071fcee 100644 --- a/src/entities/structures/powerPool.c +++ b/src/entities/structures/powerPool.c @@ -24,13 +24,11 @@ static void tick(void); static void action(void); static void touch(Entity *other); -void initPowerPool(Entity *e) +Entity *initPowerPool(void) { Structure *s; - initEntity(e); - - s = (Structure*)e; + s = createStructure(); s->type = ET_POOL; @@ -45,6 +43,8 @@ void initPowerPool(Entity *e) s->tick = tick; s->action = action; s->touch = touch; + + return (Entity*)s; } static void tick(void) diff --git a/src/entities/structures/powerPool.h b/src/entities/structures/powerPool.h index f47806a..80b9c24 100644 --- a/src/entities/structures/powerPool.h +++ b/src/entities/structures/powerPool.h @@ -20,8 +20,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../../common.h" +extern Structure *createStructure(void); extern Sprite *getSprite(char *name); -extern void initEntity(Entity *e); extern Entity *self; extern World world; diff --git a/src/entities/structures/pressurePlate.c b/src/entities/structures/pressurePlate.c index 7a218aa..69c8a56 100644 --- a/src/entities/structures/pressurePlate.c +++ b/src/entities/structures/pressurePlate.c @@ -23,13 +23,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. static void tick(void); static void touch(Entity *other); -void initPressurePlate(Entity *e) +Entity *initPressurePlate(void) { Structure *s; - initEntity(e); - - s = (Structure*)e; + s = createStructure(); s->type = ET_PRESSURE_PLATE; @@ -43,6 +41,8 @@ void initPressurePlate(Entity *e) s->tick = tick; s->touch = touch; + + return (Entity*)s; } static void tick(void) diff --git a/src/entities/structures/pressurePlate.h b/src/entities/structures/pressurePlate.h index a54d0f2..2a701bd 100644 --- a/src/entities/structures/pressurePlate.h +++ b/src/entities/structures/pressurePlate.h @@ -20,7 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../../common.h" -extern void initEntity(Entity *e); +extern Structure *createStructure(void); extern Sprite *getSprite(char *name); extern void activateEntities(char *names, int activate); extern void playSound(int snd, int ch); diff --git a/src/entities/structures/pushBlock.c b/src/entities/structures/pushBlock.c index 38c5f89..3f79b80 100644 --- a/src/entities/structures/pushBlock.c +++ b/src/entities/structures/pushBlock.c @@ -22,13 +22,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. static void activate(int active); -void initPushBlock(Entity *e) +Entity *initPushBlock(void) { Structure *s; - initEntity(e); - - s = (Structure*)e; + s = createStructure(); s->type = ET_PUSHBLOCK; @@ -39,6 +37,8 @@ void initPushBlock(Entity *e) s->flags |= EF_EXPLODES | EF_ALWAYS_PROCESS; s->activate = activate; + + return (Entity*)s; } static void activate(int active) diff --git a/src/entities/structures/pushBlock.h b/src/entities/structures/pushBlock.h index 26449d3..9c1bfbc 100644 --- a/src/entities/structures/pushBlock.h +++ b/src/entities/structures/pushBlock.h @@ -20,8 +20,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../../common.h" -extern void initEntity(Entity *e); extern void playSound(int snd, int ch); extern void addTeleportStars(Entity *e); +extern Structure *createStructure(void); extern Entity *self; diff --git a/src/entities/structures/structures.c b/src/entities/structures/structures.c index bd5a4a7..c84ff1d 100644 --- a/src/entities/structures/structures.c +++ b/src/entities/structures/structures.c @@ -29,5 +29,7 @@ Structure *createStructure(void) world.entityTail->next = (Entity*)s; world.entityTail = (Entity*)s; + initEntity((Entity*)s); + return s; } diff --git a/src/entities/structures/structures.h b/src/entities/structures/structures.h index 7c5c350..5d58a8a 100644 --- a/src/entities/structures/structures.h +++ b/src/entities/structures/structures.h @@ -20,6 +20,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../../common.h" -extern Structure *createStructure(void); +extern void initEntity(Entity *e); extern World world; diff --git a/src/entities/structures/teleporter.c b/src/entities/structures/teleporter.c index 69b3e50..5c1296c 100644 --- a/src/entities/structures/teleporter.c +++ b/src/entities/structures/teleporter.c @@ -24,23 +24,27 @@ static void action(void); static void touch(Entity *other); static void activate(int active); -void initTeleporter(Entity *e) +Entity *initTeleporter(void) { - initEntity(e); + Structure *s; - e->type = ET_TELEPORTER; + s = createStructure(); - e->flags |= EF_WEIGHTLESS | EF_NO_CLIP | EF_IGNORE_BULLETS | EF_NO_TELEPORT; - - e->plane = PLANE_FOREGROUND; - - e->isStatic = 1; - - e->active = 1; + s->type = ET_TELEPORTER; - e->action = action; - e->touch = touch; - e->activate = activate; + s->flags |= EF_WEIGHTLESS | EF_NO_CLIP | EF_IGNORE_BULLETS | EF_NO_TELEPORT; + + s->plane = PLANE_FOREGROUND; + + s->isStatic = 1; + + s->active = 1; + + s->action = action; + s->touch = touch; + s->activate = activate; + + return (Entity*)s; } static void action(void) diff --git a/src/entities/structures/teleporter.h b/src/entities/structures/teleporter.h index 7bcb2a5..c77eacd 100644 --- a/src/entities/structures/teleporter.h +++ b/src/entities/structures/teleporter.h @@ -20,12 +20,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../../common.h" -extern void initEntity(Entity *e); extern void playSound(int snd, int ch); extern void addTeleporterEffect(float x, float y); extern void teleportEntity(Entity *e, float tx, float ty); extern void observeActivation(Entity *e); extern int isOnScreen(Entity *e); extern void setGameplayMessage(int type, char *format, ...); +extern Structure *createStructure(void); extern Entity *self; diff --git a/src/structs.h b/src/structs.h index c1d74b9..595542b 100644 --- a/src/structs.h +++ b/src/structs.h @@ -95,7 +95,6 @@ struct Lookup { struct EntityDef { char name[MAX_NAME_LENGTH]; - int type; Entity *(*initFunc)(void); EntityDef *next; }; diff --git a/src/test/atlasTest.c b/src/test/atlasTest.c index 334e8e3..067664b 100644 --- a/src/test/atlasTest.c +++ b/src/test/atlasTest.c @@ -40,7 +40,7 @@ void initAtlasTest(void) loadMapData("data/maps/raw/beachApproach.raw"); - loadWorld("data/maps/underground2.json"); + loadWorld("data/maps/beachApproach.json"); } static void logic(void) diff --git a/src/world/effects.c b/src/world/effects.c index 3a54ef4..a58b46d 100644 --- a/src/world/effects.c +++ b/src/world/effects.c @@ -75,3 +75,8 @@ void throwFleshChunks(float x, float y, int amount) chunk->sprite[0] = chunk->sprite[1] = chunk->sprite[2] = fleshChunk[i % 3]; } } + +void throwDebris(float x, float y, int amount) +{ + +} diff --git a/src/world/particles.h b/src/world/particles.h index a16e4f5..dd6d41e 100644 --- a/src/world/particles.h +++ b/src/world/particles.h @@ -21,7 +21,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../common.h" extern Sprite *getSprite(char *name); -extern float wrap(float value, float low, float high); extern int rrnd(int low, int high); extern double randF(void); extern int getDistance(int x1, int y1, int x2, int y2);