Add keys to mission when starting.

This commit is contained in:
Steve 2018-02-18 09:28:25 +00:00
parent bd6b6d752a
commit 1ac2960932
4 changed files with 10 additions and 8 deletions

View File

@ -134,7 +134,7 @@ static void bobPickupItem(void)
{ {
if (i->thinkTime == 0) if (i->thinkTime == 0)
{ {
if (addItem(i)) if (addItem(i, 1))
{ {
game.stats[STAT_KEYS_FOUND]++; game.stats[STAT_KEYS_FOUND]++;
updateObjective("KEY"); updateObjective("KEY");
@ -151,7 +151,7 @@ static void bobPickupItem(void)
} }
else if (i->canBeCarried) else if (i->canBeCarried)
{ {
if (addItem(i)) if (addItem(i, 1))
{ {
if (!i->collected) if (!i->collected)
{ {

View File

@ -26,7 +26,7 @@ extern void setGameplayMessage(int type, char *format, ...);
extern void addTeleportStars(Entity *e); extern void addTeleportStars(Entity *e);
extern void initEntity(Entity *e); extern void initEntity(Entity *e);
extern Sprite *getSprite(char *name); extern Sprite *getSprite(char *name);
extern int addItem(Item *i); extern int addItem(Item *i, int num);
extern void updateObjective(char *targetName); extern void updateObjective(char *targetName);
extern Entity *self; extern Entity *self;

View File

@ -55,7 +55,7 @@ int getNumItemsCarried(void)
return rtn; return rtn;
} }
int addItem(Item *item) int addItem(Item *item, int num)
{ {
int i; int i;
@ -77,7 +77,7 @@ int addItem(Item *item)
item->flags |= EF_GONE; item->flags |= EF_GONE;
if (item->type == ET_KEY) 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); 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) 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; 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); 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) if (t->value.i > 0)
{ {
item = (Item*)createEntity(t->key); item = (Item*)createEntity(t->key);
self = (Entity*)item;
item->init(); 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); SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG, "Added %s (x%d) to inventory", item->name, item->value);
} }

View File

@ -30,5 +30,6 @@ extern int fileExists(const char *filename);
extern int lookup(char *name); extern int lookup(char *name);
extern App app; extern App app;
extern Entity *self;
extern Game game; extern Game game;
extern World world; extern World world;