From 0bc6599a95c42a9669aef310d65f36c5e867fa9d Mon Sep 17 00:00:00 2001 From: Steve Date: Sat, 27 Jan 2018 11:15:23 +0000 Subject: [PATCH] Power point and power pool. --- common.mk | 2 +- src/structs.h | 1 + src/world/entities/structures/powerPoint.c | 97 ++++++++++++++++++++++ src/world/entities/structures/powerPoint.h | 30 +++++++ src/world/entities/structures/powerPool.c | 82 ++++++++++++++++++ src/world/entities/structures/powerPool.h | 26 ++++++ 6 files changed, 237 insertions(+), 1 deletion(-) create mode 100644 src/world/entities/structures/powerPoint.c create mode 100644 src/world/entities/structures/powerPoint.h create mode 100644 src/world/entities/structures/powerPool.c create mode 100644 src/world/entities/structures/powerPool.h diff --git a/common.mk b/common.mk index 9048ca5..8c57106 100644 --- a/common.mk +++ b/common.mk @@ -37,7 +37,7 @@ OBJS += key.o keycard.o OBJS += lift.o lookup.o OBJS += main.o map.o maths.o mia.o OBJS += objectives.o -OBJS += particles.o player.o +OBJS += particles.o player.o powerPoint.o powerPool.o OBJS += quadtree.o OBJS += sound.o sprites.o OBJS += tankCommander.o tankTrack.o teeka.o text.o textures.o title.o triggers.o diff --git a/src/structs.h b/src/structs.h index d0194fd..90a3e26 100644 --- a/src/structs.h +++ b/src/structs.h @@ -148,6 +148,7 @@ struct Entity { char requiredCard[MAX_NAME_LENGTH]; char requiredKey[MAX_NAME_LENGTH]; char requiredItem[MAX_NAME_LENGTH]; + int requiredPower; long flags; SDL_Rect bounds; int sprite[3]; diff --git a/src/world/entities/structures/powerPoint.c b/src/world/entities/structures/powerPoint.c new file mode 100644 index 0000000..a71839e --- /dev/null +++ b/src/world/entities/structures/powerPoint.c @@ -0,0 +1,97 @@ +/* +Copyright (C) 2018 Parallel Realities + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#include "powerPoint.h" + +static void tick(void); +static void action(void); +static void touch(Entity *other); + +void initPowerPoint(Entity *e) +{ + initEntity(e); + + e->sprite[FACING_LEFT] = e->sprite[FACING_RIGHT] = e->sprite[FACING_DIE] = getSpriteIndex("PowerPoint"); + + e->flags |= EF_WEIGHTLESS | EF_NO_CLIP | EF_NO_ENVIRONMENT | EF_IGNORE_BULLETS; + + e->requiredPower = 100; + + e->isStatic = 1; + + e->tick = tick; + e->action = action; + e->touch = touch; +} + +static void tick(void) +{ + if (!self->active) + { + self->bobTouching = MAX(self->bobTouching - 1, 0); + + if (self->bobTouching == 0) + { + self->spriteFrame = 0; + self->spriteTime = -1; + self->thinkTime = FPS / 2; + } + } +} + +static void action(void) +{ + self->spriteFrame = MIN(self->spriteFrame + 1, 3); + + if (!self->active && self->spriteFrame == 3) + { + activateEntities(self->targetNames, 1); + + setGameplayMessage(MSG_GAMEPLAY, self->message); + + if (!dev.cheatPower) + { + world.bob->power -= self->requiredPower; + } + + self->requiredPower = 0; + + self->active = 1; + } + else + { + self->thinkTime = FPS / 2; + } +} + +static void touch(Entity *other) +{ + if (!self->active && other->type == ET_BOB && other->dx == 0) + { + if (world.bob->power < self->requiredPower && self->bobTouching == 0 && !dev.cheatPower) + { + setGameplayMessage(MSG_GAMEPLAY, "Not enough power (%d units required)", self->requiredPower); + } + else + { + self->bobTouching = 2; + } + } +} diff --git a/src/world/entities/structures/powerPoint.h b/src/world/entities/structures/powerPoint.h new file mode 100644 index 0000000..e2c0c71 --- /dev/null +++ b/src/world/entities/structures/powerPoint.h @@ -0,0 +1,30 @@ +/* +Copyright (C) 2018 Parallel Realities + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#include "../../../common.h" + +extern void initEntity(Entity *e); +extern int getSpriteIndex(char *name); +extern void activateEntities(char *names, int activate); +extern void setGameplayMessage(int type, char *format, ...); + +extern Dev dev; +extern Entity *self; +extern World world; diff --git a/src/world/entities/structures/powerPool.c b/src/world/entities/structures/powerPool.c new file mode 100644 index 0000000..903cea1 --- /dev/null +++ b/src/world/entities/structures/powerPool.c @@ -0,0 +1,82 @@ +/* +Copyright (C) 2018 Parallel Realities + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#include "powerPool.h" + +static void tick(void); +static void action(void); +static void touch(Entity *other); + +void initPowerPool(Entity *e) +{ + e->sprite[FACING_LEFT] = e->sprite[FACING_RIGHT] = e->sprite[FACING_DIE] = getSpriteIndex("PowerPool"); + + e->flags |= EF_WEIGHTLESS | EF_NO_CLIP | EF_IGNORE_BULLETS; + + e->plane = PLANE_FOREGROUND; + + e->isStatic = 1; + + e->tick = tick; + e->action = action; + e->touch = touch; +} + +static void tick(void) +{ + if (self->active) + { + self->spriteTime--; + if (self->spriteTime <= 0) + { + self->spriteFrame = (int) (1 + (rand() % 6)); + self->spriteTime = 12; + } + } +} + +static void action(void) +{ + self->active = 1; + + if (self->spriteFrame == 0) + { + self->spriteFrame = (int) (1 + (rand() % 6)); + self->spriteTime = 12; + } + + self->thinkTime = FPS * 99999; +} + +static void touch(Entity *other) +{ + if (self->active && other->type == ET_BOB && world.bob->power < world.bob->powerMax) + { + world.bob->power = MIN(world.bob->power + 0.05, world.bob->powerMax); + + if (world.bob->power == world.bob->powerMax) + { + self->thinkTime = FPS * 10; + self->spriteTime = -1; + self->spriteFrame = 0; + self->active = 0; + } + } +} diff --git a/src/world/entities/structures/powerPool.h b/src/world/entities/structures/powerPool.h new file mode 100644 index 0000000..5ae19f7 --- /dev/null +++ b/src/world/entities/structures/powerPool.h @@ -0,0 +1,26 @@ +/* +Copyright (C) 2018 Parallel Realities + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#include "../../../common.h" + +extern int getSpriteIndex(char *name); + +extern Entity *self; +extern World world;