From c3365d2766f11118daa16df5435b4d8e5ee2ff54 Mon Sep 17 00:00:00 2001 From: Steve Date: Fri, 6 May 2016 11:37:47 +0100 Subject: [PATCH] Truly random items. --- src/battle/items.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/src/battle/items.c b/src/battle/items.c index 6bfc07e..56055f8 100644 --- a/src/battle/items.c +++ b/src/battle/items.c @@ -78,17 +78,29 @@ Entity *spawnItem(char *name) void addRandomItem(int x, int y) { - Entity *e; - - e = spawnItem("smallCrate"); - e->x = x; - e->y = y; + Entity *e, *def, *item; - e->speed = 1; - e->dx = rand() % 200 - rand() % 200; - e->dy = rand() % 200 - rand() % 200; - e->dx *= 0.01; - e->dy *= 0.01; + def = item = e = NULL; + + for (e = defHead.next ; e != NULL ; e = e->next) + { + if (!def || rand() % 2) + { + def = e; + } + } + + item = spawnEntity(); + memcpy(item, def, sizeof(Entity)); + + item->x = x; + item->y = y; + item->speed = 1; + item->dx = rand() % 200 - rand() % 200; + item->dy = rand() % 200 - rand() % 200; + item->dx *= 0.01; + item->dy *= 0.01; + item->action = action; } static Entity *getItemDef(char *defName)