From b5dfab1bd5b4bc1f71a801dc6acce986d9d3e034 Mon Sep 17 00:00:00 2001 From: Steve Date: Fri, 18 Dec 2015 10:12:37 +0000 Subject: [PATCH] Added debug keys. --- common.mk | 4 +-- src/battle/ai.c | 10 ++++-- src/battle/ai.h | 1 + src/battle/capitalShips.c | 2 ++ src/battle/entities.c | 17 +++++++++ src/battle/entities.h | 1 + src/battle/player.c | 5 +++ src/battle/player.h | 1 + src/draw/draw.c | 6 +++- src/draw/draw.h | 1 + src/main.c | 12 +++++-- src/main.h | 2 ++ src/structs.h | 12 ++++++- src/system/dev.c | 75 +++++++++++++++++++++++++++++++++++++++ src/system/dev.h | 24 +++++++++++++ 15 files changed, 164 insertions(+), 9 deletions(-) create mode 100644 src/system/dev.c create mode 100644 src/system/dev.h diff --git a/common.mk b/common.mk index a39f80f..3313f52 100644 --- a/common.mk +++ b/common.mk @@ -1,6 +1,6 @@ VERSION = 0.5 REVISION = $(shell date +"%y%m%d") -DEBUG = 0 +DEBUG = $(shell stat dev 1>/dev/null 2>&1 && echo 1 || echo 0) SEARCHPATH += src/ src/battle src/draw src/game src/galaxy src/json src/system src/test vpath %.c $(SEARCHPATH) @@ -11,7 +11,7 @@ DEPS += defs.h structs.h OBJS += ai.o OBJS += battle.o bullets.o OBJS += capitalShips.o challenges.o cJSON.o -OBJS += debris.o draw.o +OBJS += debris.o dev.o draw.o OBJS += effects.o entities.o extractionPoint.o OBJS += fighters.o OBJS += galacticMap.o game.o grid.o diff --git a/src/battle/ai.c b/src/battle/ai.c index 23b798d..a6b2c00 100644 --- a/src/battle/ai.c +++ b/src/battle/ai.c @@ -410,11 +410,17 @@ static void preAttack(void) if (self->guns[0].type && (self->missiles == 0 || rand() % 50 > 0)) { - fireGuns(self); + if (!dev.noAIWeapons) + { + fireGuns(self); + } } else if (self->missiles && getDistance(self->x, self->y, self->target->x, self->target->y) >= 350) { - fireMissile(self); + if (!dev.noAIWeapons) + { + fireMissile(self); + } self->action = doAI; } diff --git a/src/battle/ai.h b/src/battle/ai.h index dc45dd1..4de072b 100644 --- a/src/battle/ai.h +++ b/src/battle/ai.h @@ -40,5 +40,6 @@ extern Entity **getAllEntsWithin(int x, int y, int w, int h, Entity *ignore); extern Battle battle; extern Colors colors; +extern Dev dev; extern Entity *self; extern Entity *player; diff --git a/src/battle/capitalShips.c b/src/battle/capitalShips.c index 47c2e5d..e54a695 100644 --- a/src/battle/capitalShips.c +++ b/src/battle/capitalShips.c @@ -406,6 +406,8 @@ static void loadComponents(Entity *parent, cJSON *components) parent->health++; } } + + parent->maxHealth = parent->health; } static void loadGuns(Entity *parent, cJSON *guns) diff --git a/src/battle/entities.c b/src/battle/entities.c index 2f3bfe2..f836d3f 100644 --- a/src/battle/entities.c +++ b/src/battle/entities.c @@ -72,8 +72,20 @@ void doEntities(void) } } + if (dev.playerImmortal) + { + player->health = player->maxHealth; + player->shield = player->maxShield; + } + for (e = battle.entityHead.next ; e != NULL ; e = e->next) { + if (dev.allImmortal) + { + e->health = e->maxHealth; + e->shield = e->maxShield; + } + if (e->active) { self = e; @@ -120,6 +132,11 @@ void doEntities(void) { if (e->action != NULL) { + if (dev.noEntityActions) + { + e->thinkTime = 2; + } + if (--e->thinkTime <= 0) { e->thinkTime = 0; diff --git a/src/battle/entities.h b/src/battle/entities.h index 552cc3b..d3b39dd 100644 --- a/src/battle/entities.h +++ b/src/battle/entities.h @@ -34,5 +34,6 @@ extern void destroyGrid(void); extern App app; extern Battle battle; +extern Dev dev; extern Entity *self; extern Entity *player; diff --git a/src/battle/player.c b/src/battle/player.c index c1144fe..4887b9b 100644 --- a/src/battle/player.c +++ b/src/battle/player.c @@ -121,6 +121,11 @@ void doPlayer(void) { selectMissionTarget(); } + + if (dev.playerUnlimitedMissiles) + { + player->missiles = 999; + } } if (battle.boostTimer == (int)BOOST_FINISHED_TIME) diff --git a/src/battle/player.h b/src/battle/player.h index c03caa8..51d9531 100644 --- a/src/battle/player.h +++ b/src/battle/player.h @@ -40,6 +40,7 @@ extern void addECMEffect(Entity *ent); extern App app; extern Battle battle; extern Colors colors; +extern Dev dev; extern Entity *player; extern Entity *self; extern Game game; diff --git a/src/draw/draw.c b/src/draw/draw.c index 7d6ec68..aeaac23 100644 --- a/src/draw/draw.c +++ b/src/draw/draw.c @@ -47,7 +47,11 @@ void prepareScene(void) void presentScene(void) { #if DEBUG - drawText(SCREEN_WIDTH / 2, SCREEN_HEIGHT - 25, 14, TA_CENTER, colors.white, "FPS: %d", app.fps); + drawText(5, SCREEN_HEIGHT - 25, 14, TA_LEFT, colors.white, "DEBUG MODE"); + if (dev.showFPS) + { + drawText(SCREEN_WIDTH / 2, SCREEN_HEIGHT - 25, 14, TA_CENTER, colors.white, "FPS: %d", dev.fps); + } #endif drawMouse(); diff --git a/src/draw/draw.h b/src/draw/draw.h index 0938b44..28ddcc9 100644 --- a/src/draw/draw.h +++ b/src/draw/draw.h @@ -25,3 +25,4 @@ extern void drawMouse(void); extern App app; extern Colors colors; +extern Dev dev; diff --git a/src/main.c b/src/main.c index 6e9bf78..6ed4b83 100644 --- a/src/main.c +++ b/src/main.c @@ -28,6 +28,7 @@ int main(int argc, char *argv[]) SDL_Event event; memset(&app, 0, sizeof(App)); + memset(&dev, 0, sizeof(Dev)); atexit(cleanup); @@ -48,7 +49,7 @@ int main(int argc, char *argv[]) initTitle(); } - app.fps = frames = td = 0; + dev.fps = frames = td = 0; then = SDL_GetTicks(); lastFrameTime = SDL_GetTicks() + 1000; @@ -104,15 +105,20 @@ int main(int argc, char *argv[]) app.delegate.draw(); + doDevKeys(); + frames++; if (SDL_GetTicks() > lastFrameTime) { - app.fps = frames; + dev.fps = frames; frames = 0; lastFrameTime = SDL_GetTicks() + 1000; - /*saveScreenshot();*/ + if (dev.takeScreenshots) + { + saveScreenshot(); + } } SDL_Delay(1); diff --git a/src/main.h b/src/main.h index d447862..2faa380 100644 --- a/src/main.h +++ b/src/main.h @@ -34,10 +34,12 @@ extern void saveScreenshot(void); extern void doMouseDown(SDL_MouseButtonEvent *event); extern void doMouseUp(SDL_MouseButtonEvent *event); extern void doMouseWheel(SDL_MouseWheelEvent *event); +extern void doDevKeys(void); App app; Colors colors; Battle battle; +Dev dev; Entity *self; Entity *player; Game game; diff --git a/src/structs.h b/src/structs.h index a990b13..6c36c48 100644 --- a/src/structs.h +++ b/src/structs.h @@ -36,6 +36,17 @@ typedef struct MessageBox MessageBox; typedef struct GridCell GridCell; typedef struct ScriptRunner ScriptRunner; +typedef struct { + int takeScreenshots; + int noAIWeapons; + int showFPS; + int playerImmortal; + int playerUnlimitedMissiles; + int noEntityActions; + int allImmortal; + int fps; +} Dev; + typedef struct { float x; float y; @@ -334,7 +345,6 @@ typedef struct { int musicVolume; int soundVolume; int vSync; - int fps; Mouse mouse; int keyboard[MAX_KEYBOARD_KEYS]; SDL_Texture *backBuffer; diff --git a/src/system/dev.c b/src/system/dev.c new file mode 100644 index 0000000..fe04806 --- /dev/null +++ b/src/system/dev.c @@ -0,0 +1,75 @@ +/* +Copyright (C) 2015 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 "dev.h" + +void doDevKeys(void) +{ + #if DEBUG + if (app.keyboard[SDL_SCANCODE_1]) + { + dev.playerImmortal = !dev.playerImmortal; + app.keyboard[SDL_SCANCODE_1] = 0; + printf("DEBUG: dev.playerImmortal=%d\n", dev.playerImmortal); + } + + if (app.keyboard[SDL_SCANCODE_2]) + { + dev.playerUnlimitedMissiles = !dev.playerUnlimitedMissiles; + app.keyboard[SDL_SCANCODE_2] = 0; + printf("DEBUG: dev.playerUnlimitedMissiles=%d\n", dev.playerUnlimitedMissiles); + } + + if (app.keyboard[SDL_SCANCODE_3]) + { + dev.noAIWeapons = !dev.noAIWeapons; + app.keyboard[SDL_SCANCODE_3] = 0; + printf("DEBUG: dev.noAIWeapons=%d\n", dev.noAIWeapons); + } + + if (app.keyboard[SDL_SCANCODE_4]) + { + dev.noEntityActions = !dev.noEntityActions; + app.keyboard[SDL_SCANCODE_4] = 0; + printf("DEBUG: dev.noEntityActions=%d\n", dev.noEntityActions); + } + + if (app.keyboard[SDL_SCANCODE_5]) + { + dev.allImmortal = !dev.allImmortal; + app.keyboard[SDL_SCANCODE_5] = 0; + printf("DEBUG: dev.allImmortal=%d\n", dev.allImmortal); + } + + if (app.keyboard[SDL_SCANCODE_9]) + { + dev.showFPS = !dev.showFPS; + app.keyboard[SDL_SCANCODE_9] = 0; + printf("DEBUG: dev.showFPS=%d\n", dev.showFPS); + } + + if (app.keyboard[SDL_SCANCODE_0]) + { + dev.takeScreenshots = !dev.takeScreenshots; + app.keyboard[SDL_SCANCODE_0] = 0; + printf("DEBUG: dev.takeScreenshots=%d\n", dev.takeScreenshots); + } + #endif +} diff --git a/src/system/dev.h b/src/system/dev.h new file mode 100644 index 0000000..5b4a97c --- /dev/null +++ b/src/system/dev.h @@ -0,0 +1,24 @@ +/* +Copyright (C) 2015 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 App app; +extern Dev dev;