tbftss/src/game/fighterDatabase.c

222 lines
5.2 KiB
C
Raw Normal View History

2017-08-07 20:14:43 +02:00
/*
2019-01-01 17:14:11 +01:00
Copyright (C) 2015-2019 Parallel Realities
2017-08-07 20:14:43 +02:00
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 "fighterDatabase.h"
2017-08-09 19:21:26 +02:00
static void prevFighter(void);
static void nextFighter(void);
static int countFighterGuns(Entity *fighter, int type);
2017-08-12 08:42:58 +02:00
static void setNumDestroyed(void);
2017-08-09 19:21:26 +02:00
2017-08-07 20:14:43 +02:00
static int page;
static int maxPages;
2017-08-12 08:42:58 +02:00
static int numDestroyed;
2017-08-07 20:14:43 +02:00
static Widget *prev;
static Widget *next;
static char *DB_TEXT;
static char *PAGE_TEXT;
static char *COMMON_TEXT;
2017-08-12 09:33:41 +02:00
static char *DESTROYED_TEXT;
static char *AFFILIATION_TEXT;
static char *ARMOUR_TEXT;
static char *SHIELD_TEXT;
static char *SPEED_TEXT;
static char *MISSILES_TEXT;
2018-05-06 19:50:11 +02:00
static char *MISSILE_NUM_TEXT;
2017-08-09 19:21:26 +02:00
static const char *gunName[BT_MAX];
static Entity **dbFighters;
2017-08-10 09:44:19 +02:00
static float rotation;
2017-08-07 20:14:43 +02:00
void initFighterDatabase(void)
{
DB_TEXT = _("Fighter Database");
PAGE_TEXT = _("Page %d / %d");
2017-08-09 19:21:26 +02:00
COMMON_TEXT = _("(Common)");
2017-08-12 09:33:41 +02:00
DESTROYED_TEXT = _("Destroyed");
AFFILIATION_TEXT = _("Affiliation");
ARMOUR_TEXT = _("Armour");
SHIELD_TEXT = _("Shield");
SPEED_TEXT = _("Speed");
MISSILES_TEXT = _("Missiles");
2018-05-06 19:50:11 +02:00
MISSILE_NUM_TEXT = _("Missiles x %d");
2017-08-12 09:33:41 +02:00
2017-08-09 19:21:26 +02:00
dbFighters = getDBFighters(&maxPages);
gunName[BT_NONE] = "";
gunName[BT_PARTICLE] = _("Particle Cannon");
gunName[BT_PLASMA] = _("Plasma Cannon");
gunName[BT_LASER] = _("Laser Cannon");
gunName[BT_MAG] = _("Mag Cannon");
gunName[BT_ROCKET] = _("Rockets");
gunName[BT_MISSILE] = _("Missiles");
2017-08-10 09:44:19 +02:00
rotation = 0;
2017-08-09 19:21:26 +02:00
}
void destroyFighterDatabase(void)
{
free(dbFighters);
2017-08-07 20:14:43 +02:00
}
void initFighterDatabaseDisplay(void)
{
page = 0;
prev = getWidget("prev", "fighterDB");
prev->action = prevFighter;
next = getWidget("next", "fighterDB");
next->action = nextFighter;
2017-08-12 08:42:58 +02:00
setNumDestroyed();
2017-08-07 20:14:43 +02:00
}
2017-08-10 09:44:19 +02:00
void doFighterDatabase(void)
{
rotation++;
}
2017-08-07 20:14:43 +02:00
void drawFighterDatabase(void)
{
SDL_Rect r;
2017-08-09 19:21:26 +02:00
Entity *fighter;
int i, y, numCannons;
2017-08-07 20:14:43 +02:00
SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND);
SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 128);
SDL_RenderFillRect(app.renderer, NULL);
SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE);
2018-12-17 09:30:47 +01:00
SDL_SetRenderTarget(app.renderer, app.uiBuffer);
2017-08-10 09:44:19 +02:00
r.w = 700;
2017-08-07 20:14:43 +02:00
r.h = 650;
2018-12-13 08:59:31 +01:00
r.x = (UI_WIDTH / 2) - r.w / 2;
r.y = (UI_HEIGHT / 2) - r.h / 2;
2017-08-07 20:14:43 +02:00
2018-12-11 09:24:25 +01:00
SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 255);
2017-08-07 20:14:43 +02:00
SDL_RenderFillRect(app.renderer, &r);
SDL_SetRenderDrawColor(app.renderer, 200, 200, 200, 255);
SDL_RenderDrawRect(app.renderer, &r);
2018-12-13 08:59:31 +01:00
drawText(UI_WIDTH / 2, 50, 28, TA_CENTER, colors.white, DB_TEXT);
2017-08-07 20:14:43 +02:00
2018-12-13 08:59:31 +01:00
drawText(UI_WIDTH / 2, 90, 16, TA_CENTER, colors.lightGrey, PAGE_TEXT, page + 1, (int)maxPages);
2017-08-07 20:14:43 +02:00
2017-08-09 19:21:26 +02:00
fighter = dbFighters[page];
2018-12-13 08:59:31 +01:00
drawText(UI_WIDTH / 2, 130, 28, TA_CENTER, colors.white, fighter->name);
2017-08-09 19:21:26 +02:00
2017-08-10 09:44:19 +02:00
blitRotated(fighter->texture, r.x + (r.w / 2), 250, rotation);
if (fighter->flags & EF_COMMON_FIGHTER)
{
2018-12-13 08:59:31 +01:00
drawText(UI_WIDTH / 2, 170, 18, TA_CENTER, colors.darkGrey, COMMON_TEXT);
drawText(r.x + (r.w / 2), 290, 18, TA_CENTER, colors.lightGrey, "%s: %d", DESTROYED_TEXT, numDestroyed);
}
2017-08-12 08:42:58 +02:00
2017-08-12 09:33:41 +02:00
drawText(r.x + 25, 200, 22, TA_LEFT, colors.white, "%s: %s", AFFILIATION_TEXT, fighter->affiliation);
drawText(r.x + 25, 240, 22, TA_LEFT, colors.white, "%s: %d", ARMOUR_TEXT, fighter->health);
drawText(r.x + 25, 280, 22, TA_LEFT, colors.white, "%s: %d", SHIELD_TEXT, fighter->shield);
drawText(r.x + 25, 320, 22, TA_LEFT, colors.white, "%s: %.0f", SPEED_TEXT, ((fighter->speed * fighter->speed) * FPS));
2017-08-09 19:21:26 +02:00
y = 200;
for (i = 1 ; i < BT_MAX ; i++)
{
numCannons = countFighterGuns(fighter, i);
if (numCannons > 0)
{
drawText(r.x + r.w - 25, y, 22, TA_RIGHT, colors.white, "%s x %d", gunName[i], numCannons);
2017-08-10 09:44:19 +02:00
y += 40;
2017-08-09 19:21:26 +02:00
}
}
if (fighter->missiles > 0)
{
2018-05-06 19:50:11 +02:00
drawText(r.x + r.w - 25, y, 22, TA_RIGHT, colors.white, MISSILE_NUM_TEXT, fighter->missiles);
2017-08-09 19:21:26 +02:00
}
2017-08-10 09:44:19 +02:00
y = MAX(y, 320) + 75;
2018-12-06 09:37:19 +01:00
app.textWidth = r.w - 50;
2017-08-10 09:44:19 +02:00
drawText(r.x + 25, y, 18, TA_LEFT, colors.white, fighter->description);
2018-12-06 09:37:19 +01:00
app.textWidth = 0;
2017-08-09 19:21:26 +02:00
2017-08-07 20:14:43 +02:00
drawWidgets("fighterDB");
2018-12-12 09:32:32 +01:00
SDL_SetRenderTarget(app.renderer, app.backBuffer);
2017-08-07 20:14:43 +02:00
}
2017-08-09 19:21:26 +02:00
static int countFighterGuns(Entity *fighter, int type)
{
int i, num;
num = 0;
for (i = 0 ; i < MAX_FIGHTER_GUNS ; i++)
{
if (fighter->guns[i].type == type)
{
num++;
}
}
return num;
}
2017-08-07 20:14:43 +02:00
static void prevFighter(void)
{
2017-08-09 19:21:26 +02:00
page = mod(page - 1, maxPages);
2017-08-12 08:42:58 +02:00
setNumDestroyed();
2017-08-07 20:14:43 +02:00
}
static void nextFighter(void)
{
2017-08-09 19:21:26 +02:00
page = mod(page + 1, maxPages);
2017-08-12 08:42:58 +02:00
setNumDestroyed();
}
static void setNumDestroyed(void)
{
Tuple *t;
Entity *fighter;
fighter = dbFighters[page];
numDestroyed = 0;
for (t = game.fighterStatHead.next ; t != NULL ; t = t->next)
{
if (strcmp(t->key, fighter->name) == 0)
{
numDestroyed = t->value;
return;
}
}
2017-08-07 20:14:43 +02:00
}