diff --git a/src/entities/blobs/bob.c b/src/entities/blobs/bob.c index 5843c88..8aae508 100644 --- a/src/entities/blobs/bob.c +++ b/src/entities/blobs/bob.c @@ -58,8 +58,6 @@ Entity *initBob(void) initEntity((Entity*)b); b->type = ET_BOB; - - b->itemTail = &b->itemHead; walkSprite[FACING_LEFT] = getSprite("BobLeft"); walkSprite[FACING_RIGHT] = getSprite("BobRight"); @@ -626,20 +624,6 @@ void die(void) } } -void addBobItem(Item *i) -{ - -} - -int numCarriedItems(void) -{ - return 0; -} - -void dropCarriedItems(void) -{ -} - static SDL_Rect *getCurrentSprite(void) { if (world.bob->alive == ALIVE_ALIVE && world.bob->stunTimer <= 0) diff --git a/src/entities/blobs/mia.c b/src/entities/blobs/mia.c index 78f1a26..afe63cd 100644 --- a/src/entities/blobs/mia.c +++ b/src/entities/blobs/mia.c @@ -23,7 +23,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. static void init(void); static void reset(void); static void tick(void); -static void nothing(void); static void touch(Entity *other); static void preTeleport(void); static void teleport(void); @@ -54,7 +53,6 @@ Entity *initMIA(void) m->spriteTime = rand() % 180; m->init = init; - m->action = nothing; m->reset = reset; m->tick = tick; m->touch = touch; @@ -93,7 +91,7 @@ static void tick(void) m->shudderTimer = 2; } - if (m->action != nothing) + if (!m->isMissionTarget) { m->starTimer--; if (m->starTimer <= 0) @@ -110,7 +108,7 @@ static void touch(Entity *other) m = (MIA*)self; - if (m->action == nothing && other == (Entity*)world.bob) + if (m->isMissionTarget && other == (Entity*)world.bob) { m->action = preTeleport; m->teleportTimer = FPS * 3; @@ -152,11 +150,6 @@ static void teleport(void) } } -static void nothing(void) -{ - -} - static void load(cJSON *root) { MIA *m; diff --git a/src/entities/items/item.c b/src/entities/items/item.c index 499d72d..c55737f 100644 --- a/src/entities/items/item.c +++ b/src/entities/items/item.c @@ -134,8 +134,7 @@ static void bobPickupItem(void) { if (i->thinkTime == 0) { - i->alive = ALIVE_DEAD; - addKey(i->name); + addItem(i); game.keysFound++; updateObjective("KEY"); @@ -150,17 +149,13 @@ static void bobPickupItem(void) } else if (i->canBeCarried) { - if (numCarriedItems() < MAX_ITEMS) + if (addItem(i)) { - i->flags |= EF_GONE; - if (!i->collected) { updateObjective(i->name); i->collected = 1; } - - addBobItem(i); setGameplayMessage(MSG_STANDARD, _("Picked up a %s"), i->name); diff --git a/src/entities/items/item.h b/src/entities/items/item.h index 114d4d9..8abc4d5 100644 --- a/src/entities/items/item.h +++ b/src/entities/items/item.h @@ -26,9 +26,8 @@ extern void setGameplayMessage(int type, char *format, ...); extern void addTeleportStars(Entity *e); extern void initEntity(Entity *e); extern Sprite *getSprite(char *name); -extern void addBobItem(Item *i); +extern int addItem(Item *i); extern int numCarriedItems(void); -extern void addKey(char *name); extern void updateObjective(char *targetName); extern Entity *self; diff --git a/src/entities/structures/door.c b/src/entities/structures/door.c index f0bdf98..1f8dd96 100644 --- a/src/entities/structures/door.c +++ b/src/entities/structures/door.c @@ -218,33 +218,33 @@ static void openWithKey(void) s = (Structure*)self; - if (hasItem(s->requiredItem)) + if (hasItem(s->requiredItem) || dev.cheatKeys) { - if (s->thinkTime <= 0) - { - setGameplayMessage(MSG_GAMEPLAY, _("%s required"), s->requiredItem); + removeItem(s->requiredItem); - playSound(SND_DENIED, CH_MECHANICAL); + setGameplayMessage(MSG_GAMEPLAY, _("%s removed"), s->requiredItem); + + STRNCPY(s->requiredItem, "", MAX_NAME_LENGTH); + s->isLocked = 0; + + if (s->state != DOOR_OPEN) + { + playSound(SND_DOOR_START, CH_MECHANICAL); } - s->thinkTime = 2; - + s->state = DOOR_OPEN; + return; } - - removeItem(s->requiredItem); - - setGameplayMessage(MSG_GAMEPLAY, _("%s removed"), s->requiredItem); - - STRNCPY(s->requiredItem, "", MAX_NAME_LENGTH); - s->isLocked = 0; - - if (s->state != DOOR_OPEN) + + if (s->thinkTime <= 0) { - playSound(SND_DOOR_START, CH_MECHANICAL); + setGameplayMessage(MSG_GAMEPLAY, _("%s required"), s->requiredItem); + + playSound(SND_DENIED, CH_MECHANICAL); } - s->state = DOOR_OPEN; + s->thinkTime = 2; } static int isOpening(void) diff --git a/src/game/game.c b/src/game/game.c index af443a7..19a3e01 100644 --- a/src/game/game.c +++ b/src/game/game.c @@ -64,23 +64,84 @@ void addDefeatedTarget(char *name) } } -void addKey(char *name) +int addItem(Entity *item) { + int i; + for (i = 0 ; i < MAX_ITEMS ; i++) + { + if (world.bob->items[i] == NULL) + { + world.bob->items[i] = item; + item->flags |= EF_GONE; + return 1; + } + } + + return 0; } int hasItem(char *name) { + int i; + Item *item; + + for (i = 0 ; i < MAX_ITEMS ; i++) + { + item = (Item*)world.bob->items[i]; + + if (item != NULL && strcmp(item->name, name) == 0) + { + return 1; + } + } + return 0; } Entity *getItem(char *name) { + int i; + Item *item; + + for (i = 0 ; i < MAX_ITEMS ; i++) + { + item = (Item*)world.bob->items[i]; + + if (item != NULL && strcmp(item->name, name) == 0) + { + return world.bob->items[i]; + } + } + return NULL; } void removeItem(char *name) { + int i; + Item *item; + + for (i = 0 ; i < MAX_ITEMS ; i++) + { + item = (Item*)world.bob->items[i]; + + if (item != NULL && strcmp(item->name, name) == 0) + { + item->flags &= ~EF_GONE; + item->alive = ALIVE_DEAD; + } + } +} + +void dropCarriedItems(void) +{ + int i; + + for (i = 0 ; i < MAX_ITEMS ; i++) + { + + } } static void loadMetaInfo(void) diff --git a/src/game/game.h b/src/game/game.h index 5cfe87a..a64e7a6 100644 --- a/src/game/game.h +++ b/src/game/game.h @@ -24,3 +24,4 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. extern char *readFile(const char *filename); extern Game game; +extern World world; diff --git a/src/structs.h b/src/structs.h index 39fa02f..38b709f 100644 --- a/src/structs.h +++ b/src/structs.h @@ -214,7 +214,7 @@ struct Bob { int power, powerMax; int jpEffectTimer; PointF checkpoints[MAX_CHECKPOINTS]; - Item itemHead, *itemTail; + Entity *items[MAX_ITEMS]; }; struct Structure { diff --git a/src/world/world.c b/src/world/world.c index 7f6d1de..2f1330c 100644 --- a/src/world/world.c +++ b/src/world/world.c @@ -67,6 +67,9 @@ void initWorld(void) app.delegate.draw = draw; startMission(); + + world.bob->x = 166 * MAP_TILE_SIZE; + world.bob->y = 98 * MAP_TILE_SIZE; } static void logic(void)