diff --git a/src/entities/items/battery.c b/src/entities/items/battery.c index afa8a1c..c389488 100644 --- a/src/entities/items/battery.c +++ b/src/entities/items/battery.c @@ -20,19 +20,23 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "battery.h" -void initBattery(Entity *e) +static void touch(Entity *other); + +Item *initBattery(void) { Item *i; - initConsumable(e); + i = initConsumable(); - i = (Item*)e; - i->spriteFrame = 0; i->spriteTime = -1; + + i->touch = touch; + + return i; } -void touch(Entity *other) +static void touch(Entity *other) { Item *i; diff --git a/src/entities/items/battery.h b/src/entities/items/battery.h index 1a13b49..6ca76ad 100644 --- a/src/entities/items/battery.h +++ b/src/entities/items/battery.h @@ -20,10 +20,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../../common.h" +extern Item *initConsumable(void); extern void playSound(int snd, int ch); extern void pickupItem(void); extern void setGameplayMessage(int type, char *format, ...); -extern void initConsumable(Entity *e); extern int touchedPlayer(Entity *e); extern Entity *self; diff --git a/src/entities/items/cherry.c b/src/entities/items/cherry.c index 09d57fe..26873c5 100644 --- a/src/entities/items/cherry.c +++ b/src/entities/items/cherry.c @@ -22,11 +22,15 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. static void touch(Entity *other); -void initCherry(Entity *e) +Item *initCherry(void) { - initConsumable(e); + Item *i; - e->touch = touch; + i = initConsumable(); + + i->touch = touch; + + return i; } static void touch(Entity *other) diff --git a/src/entities/items/cherry.h b/src/entities/items/cherry.h index 0b13701..c98a6c0 100644 --- a/src/entities/items/cherry.h +++ b/src/entities/items/cherry.h @@ -20,7 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../../common.h" -extern void initConsumable(Entity *e); +extern Item *initConsumable(void); extern void setGameplayMessage(int type, char *format, ...); extern void playSound(int snd, int ch); extern int touchedPlayer(Entity *other); diff --git a/src/entities/items/consumable.c b/src/entities/items/consumable.c index dcd3590..3a76f90 100644 --- a/src/entities/items/consumable.c +++ b/src/entities/items/consumable.c @@ -23,18 +23,25 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. static void tick(void); static void die(void); -void initConsumable(Entity *e) +Item *initConsumable(void) { - initEntity(e); + Item *i; - e->type = ET_CONSUMABLE; + i = malloc(sizeof(Item)); + memset(i, 0, sizeof(Item)); - e->flags |= EF_IGNORE_BULLETS; + initEntity((Entity*)i); + + i->type = ET_CONSUMABLE; + + i->flags |= EF_IGNORE_BULLETS; - e->health = FPS * 10; + i->health = FPS * 10; - e->tick = tick; - e->die = die; + i->tick = tick; + i->die = die; + + return i; } static void tick(void) diff --git a/src/entities/items/weaponPickup.c b/src/entities/items/weaponPickup.c index 7c84f1c..88e56fa 100644 --- a/src/entities/items/weaponPickup.c +++ b/src/entities/items/weaponPickup.c @@ -20,20 +20,34 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "weaponPickup.h" -static void (*itemTick)(void); +static void (*superTick)(void); +static void init(void); static void tick(void); static void touch(Entity *other); -void initWeaponPickup(Entity *e) +Entity *initWeaponPickup(void) { Item *i; - initConsumable(e); - - i = (Item*)e; + i = (Item*)initConsumable(); i->weaponType = WPN_PISTOL; + + superTick = i->tick; + i->init = init; + i->tick = tick; + i->touch = touch; + + return (Entity*)i; +} + +static void init(void) +{ + Item *i; + + i = (Item*)self; + i->sprite[0] = i->sprite[1] = i->sprite[2] = getSprite("Weapon"); i->spriteFrame = i->weaponType; i->spriteTime = -1; @@ -42,11 +56,6 @@ void initWeaponPickup(Entity *e) { i->health = 9999; } - - itemTick = i->tick; - - i->tick = tick; - i->touch = touch; } static void tick(void) @@ -55,7 +64,7 @@ static void tick(void) i = (Item*)self; - itemTick(); + superTick(); if (i->provided && i->alive == ALIVE_ALIVE) { diff --git a/src/entities/items/weaponPickup.h b/src/entities/items/weaponPickup.h index 47cd7c5..af0b559 100644 --- a/src/entities/items/weaponPickup.h +++ b/src/entities/items/weaponPickup.h @@ -22,11 +22,11 @@ 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 initConsumable(Entity *e); extern Sprite *getSprite(char *name); extern void pickupItem(void); extern int touchedPlayer(Entity *e); extern const char *getWeaponName(int i); +extern Entity *initConsumable(void); extern Entity *self; extern World world; diff --git a/src/world/entities.c b/src/world/entities.c index 6bbf479..cc3188f 100644 --- a/src/world/entities.c +++ b/src/world/entities.c @@ -231,7 +231,7 @@ void drawEntities(int plane) for (i = 0, self = candidates[i] ; self != NULL ; self = candidates[++i]) { - draw = !(self->flags & EF_GONE) && self->plane == plane; + draw = self->isOnScreen && !(self->flags & EF_GONE) && self->plane == plane; if (draw) { diff --git a/src/world/items.c b/src/world/items.c index 19dea77..f4d088d 100644 --- a/src/world/items.c +++ b/src/world/items.c @@ -39,34 +39,22 @@ void initItems(void) void addRandomWeapon(float x, float y) { - Item *wpn; + Item *i; int type; - - wpn = malloc(sizeof(Item)); - memset(wpn, 0, sizeof(Item)); - world.entityTail->next = (Entity*)wpn; - world.entityTail = (Entity*)wpn; - - wpn->x = x; - wpn->y = y; - - type = getRandomPlayerWeaponAt(wpn->x, wpn->y); - - switch (type) - { - case 0: - wpn->touch = NULL; - break; - - default: - break; - } - - wpn->sprite[0] = wpn->sprite[1] = wpn->sprite[2] = wpnIconSprite; - wpn->spriteFrame = type; - wpn->spriteTime = -1; - throwItem(wpn); + i = initWeaponPickup(); + + i->x = x; + i->y = y; + + type = getRandomPlayerWeaponAt(i->x, i->y); + + i->weaponType = type; + i->sprite[0] = i->sprite[1] = i->sprite[2] = wpnIconSprite; + i->spriteFrame = type; + i->spriteTime = -1; + + throwItem(i); } static int getRandomPlayerWeaponAt(int x, int y) @@ -79,7 +67,7 @@ static int getRandomPlayerWeaponAt(int x, int y) { type = WPN_PISTOL; } - else if (type == WPN_PISTOL && rand() < 0.25) + else if (type == WPN_PISTOL && rand() % 100 < 25) { type = getRandomPlayerWeapon(world.isBossMission); } @@ -92,34 +80,32 @@ void dropRandomCherry(float x, float y) Item *i; int r; - i = malloc(sizeof(Item)); - memset(i, 0, sizeof(Item)); - world.entityTail->next = (Entity*)i; - world.entityTail = (Entity*)i; + i = initCherry(); r = rand() % 100; if (r < 1) { - STRNCPY(i->name, "bunch of cherries", MAX_NAME_LENGTH); + STRNCPY(i->name, _("bunch of cherries"), MAX_NAME_LENGTH); i->value = 10; i->sprite[0] = i->sprite[1] = i->sprite[2] = cherrySprite[2]; } else if (r < 10) { - STRNCPY(i->name, "pair of cherries", MAX_NAME_LENGTH); + STRNCPY(i->name, _("pair of cherries"), MAX_NAME_LENGTH); i->value = 3; i->sprite[0] = i->sprite[1] = i->sprite[2] = cherrySprite[1]; } else { - STRNCPY(i->name, "small cherry", MAX_NAME_LENGTH); + STRNCPY(i->name, _("small cherry"), MAX_NAME_LENGTH); i->value = 1; i->sprite[0] = i->sprite[1] = i->sprite[2] = cherrySprite[0]; } i->x = x; i->y = y; + i->spriteFrame = 0; throwItem(i); } @@ -128,32 +114,29 @@ void dropBattery(float x, float y) { Item *i; int r; - - i = malloc(sizeof(Item)); - memset(i, 0, sizeof(Item)); - world.entityTail->next = (Entity*)i; - world.entityTail = (Entity*)i; + + i = initBattery(); r = rand() % 100; if (r < 1) { - STRNCPY(i->name, "full battery", MAX_NAME_LENGTH); + STRNCPY(i->name, _("full battery"), MAX_NAME_LENGTH); i->value = 4; } else if (r < 10) { - STRNCPY(i->name, "battery", MAX_NAME_LENGTH); + STRNCPY(i->name, _("battery"), MAX_NAME_LENGTH); i->value = 3; } else if (r < 25) { - STRNCPY(i->name, "used battery", MAX_NAME_LENGTH); + STRNCPY(i->name, _("used battery"), MAX_NAME_LENGTH); i->value = 2; } else { - STRNCPY(i->name, "weak battery", MAX_NAME_LENGTH); + STRNCPY(i->name, _("weak battery"), MAX_NAME_LENGTH); i->value = 1; } @@ -163,6 +146,8 @@ void dropBattery(float x, float y) i->x = x; i->y = y; + + i->animate(); throwItem(i); } diff --git a/src/world/items.h b/src/world/items.h index 4354839..a022ac2 100644 --- a/src/world/items.h +++ b/src/world/items.h @@ -20,9 +20,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../common.h" +extern Entity *initItem(void); extern int rrnd(int low, int high); extern int getRandomPlayerWeapon(int excludeGrenades); extern Sprite *getSprite(char *name); extern void addRandomItems(float x, float y); +extern Item *initBattery(void); +extern Item *initCherry(void); +extern Item * initWeaponPickup(void); extern World world;