diff --git a/src/entities/items/item.c b/src/entities/items/item.c index ea88f23..f14ac23 100644 --- a/src/entities/items/item.c +++ b/src/entities/items/item.c @@ -134,7 +134,7 @@ static void bobPickupItem(void) { if (i->thinkTime == 0) { - if (addItem(i)) + if (addItem(i, 1)) { game.stats[STAT_KEYS_FOUND]++; updateObjective("KEY"); @@ -151,7 +151,7 @@ static void bobPickupItem(void) } else if (i->canBeCarried) { - if (addItem(i)) + if (addItem(i, 1)) { if (!i->collected) { diff --git a/src/entities/items/item.h b/src/entities/items/item.h index 50744d0..f64c1fa 100644 --- a/src/entities/items/item.h +++ b/src/entities/items/item.h @@ -26,7 +26,7 @@ extern void setGameplayMessage(int type, char *format, ...); extern void addTeleportStars(Entity *e); extern void initEntity(Entity *e); extern Sprite *getSprite(char *name); -extern int addItem(Item *i); +extern int addItem(Item *i, int num); extern void updateObjective(char *targetName); extern Entity *self; diff --git a/src/game/game.c b/src/game/game.c index 0db1084..ec24881 100644 --- a/src/game/game.c +++ b/src/game/game.c @@ -55,7 +55,7 @@ int getNumItemsCarried(void) return rtn; } -int addItem(Item *item) +int addItem(Item *item, int num) { int i; @@ -77,7 +77,7 @@ int addItem(Item *item) item->flags |= EF_GONE; if (item->type == ET_KEY) { - item->value = 1; + item->value = num; } SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG, "Added %s (value=%d)", item->name, world.bob->items[i]->value); @@ -201,7 +201,7 @@ static void addKeyToStash(Item *item) if (t->value.i == 0) { - STRNCPY(t->key, item->name, MAX_NAME_LENGTH); + STRNCPY(t->key, item->sprite[0]->name, MAX_NAME_LENGTH); t->value.i = item->value; SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG, "Added %s (x%d) to stash", t->key, t->value.i); @@ -224,10 +224,11 @@ void addKeysFromStash(void) if (t->value.i > 0) { item = (Item*)createEntity(t->key); + self = (Entity*)item; item->init(); - item->value = t->value.i; + item->animate(); - addItem(item); + addItem(item, t->value.i); SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG, "Added %s (x%d) to inventory", item->name, item->value); } diff --git a/src/game/game.h b/src/game/game.h index 9e44cb8..f16eb43 100644 --- a/src/game/game.h +++ b/src/game/game.h @@ -30,5 +30,6 @@ extern int fileExists(const char *filename); extern int lookup(char *name); extern App app; +extern Entity *self; extern Game game; extern World world;