tbftss/src/battle/radar.c

150 lines
3.6 KiB
C
Raw Normal View History

2015-10-20 13:51:49 +02:00
/*
2018-04-29 11:01:09 +02:00
Copyright (C) 2015-2018 Parallel Realities
2015-10-20 13:51:49 +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 "radar.h"
2018-12-06 09:37:19 +01:00
static AtlasImage *radarTexture;
static AtlasImage *radarWarningTexture;
2015-11-26 11:54:40 +01:00
static int radarRanges[] = {20, 40, 60};
2016-07-19 10:26:19 +02:00
static char *CAUTION_TEXT;
void initRadar(void)
{
2018-12-06 09:37:19 +01:00
radarTexture = getAtlasImage("gfx/hud/radar.png");
radarWarningTexture = getAtlasImage("gfx/hud/radarWarning.png");
2016-06-02 10:49:58 +02:00
/* medium range by default */
battle.radarRange = 1;
2016-07-19 10:26:19 +02:00
CAUTION_TEXT = _("Caution: Leaving battle area - turn around.");
}
2015-10-20 13:51:49 +02:00
void drawRadar(void)
{
SDL_Rect r;
2015-12-14 09:15:41 +01:00
Entity *e;
2016-05-15 09:19:26 +02:00
int dist, inRange, blink;
2015-10-20 13:51:49 +02:00
2018-12-13 08:59:31 +01:00
blit(radarTexture, app.winWidth - 85, app.winHeight - 85, 1);
2015-10-20 13:51:49 +02:00
2018-12-13 08:59:31 +01:00
drawText(app.winWidth - 160, app.winHeight - 30, 14, TA_RIGHT, colors.white, "%dx", battle.radarRange + 1);
2015-11-26 11:54:40 +01:00
2015-10-20 13:51:49 +02:00
r.w = r.h = 3;
2016-05-15 09:19:26 +02:00
blink = battle.stats[STAT_TIME] % 60 < 30;
2015-12-14 09:15:41 +01:00
for (e = battle.entityHead.next ; e != NULL ; e = e->next)
2015-10-20 13:51:49 +02:00
{
2016-03-30 23:41:34 +02:00
dist = getDistance(e->x, e->y, player->x, player->y);
if (e->active)
2015-10-20 13:51:49 +02:00
{
2016-03-30 23:41:34 +02:00
inRange = (!(e->flags & EF_SHORT_RADAR_RANGE)) ? (dist / radarRanges[battle.radarRange]) < 70 : dist < 500;
2015-10-20 13:51:49 +02:00
2016-03-30 23:41:34 +02:00
if (inRange)
2015-10-20 13:51:49 +02:00
{
2018-12-13 08:59:31 +01:00
r.x = app.winWidth - 85;
r.y = app.winHeight - 85;
2016-03-30 23:41:34 +02:00
r.x -= (player->x - e->x) / radarRanges[battle.radarRange];
r.y -= (player->y - e->y) / radarRanges[battle.radarRange];
r.x--;
r.y--;
2016-05-15 09:19:26 +02:00
if (e->side == SIDE_NONE)
2016-03-30 23:41:34 +02:00
{
2016-05-15 09:19:26 +02:00
SDL_SetRenderDrawColor(app.renderer, 255, 255, 255, 255);
2016-03-30 23:41:34 +02:00
}
2016-05-15 09:19:26 +02:00
else if (e->side == player->side)
2016-03-30 23:41:34 +02:00
{
2016-05-15 09:19:26 +02:00
SDL_SetRenderDrawColor(app.renderer, 0, 255, 0, 255);
2016-03-30 23:41:34 +02:00
}
2016-05-15 09:19:26 +02:00
else
2016-03-30 23:41:34 +02:00
{
2016-05-15 09:19:26 +02:00
SDL_SetRenderDrawColor(app.renderer, 255, 0, 0, 255);
2016-04-01 15:20:03 +02:00
}
2016-04-14 12:56:42 +02:00
if (e->type == ET_MINE || e->type == ET_SHADOW_MINE || e->type == ET_JUMPGATE || (e->owner && e->owner->type == ET_JUMPGATE))
2016-04-01 15:20:03 +02:00
{
SDL_SetRenderDrawColor(app.renderer, 255, 255, 255, 255);
2016-03-30 23:41:34 +02:00
}
2016-05-15 09:19:26 +02:00
if (blink)
{
if (e == player->target || e == battle.missionTarget)
{
SDL_SetRenderDrawColor(app.renderer, 255, 255, 0, 255);
}
if (e->flags & EF_DISABLED)
{
SDL_SetRenderDrawColor(app.renderer, 0, 192, 255, 255);
}
}
2016-03-30 23:41:34 +02:00
SDL_RenderFillRect(app.renderer, &r);
2015-10-20 13:51:49 +02:00
}
}
}
}
void drawRadarRangeWarning(void)
{
int x, y, leaving;
2018-12-13 08:59:31 +01:00
x = (int)player->x / (app.winWidth / 2);
y = (int)player->y / (app.winHeight / 2);
leaving = 0;
if (x <= 2 && player->dx < 0)
{
2018-12-13 08:59:31 +01:00
blitRotated(radarWarningTexture, app.winWidth - 85, app.winHeight - 85, 270);
leaving = 1;
}
if (y <= 3 && player->dy < 0)
{
2018-12-13 08:59:31 +01:00
blitRotated(radarWarningTexture, app.winWidth - 85, app.winHeight - 85, 0);
leaving = 1;
}
if (x >= BATTLE_AREA_CELLS - 2 && player->dx > 0)
{
2018-12-13 08:59:31 +01:00
blitRotated(radarWarningTexture, app.winWidth - 85, app.winHeight - 85, 90);
leaving = 1;
}
if (y >= BATTLE_AREA_CELLS - 3 && player->dy > 0)
{
2018-12-13 08:59:31 +01:00
blitRotated(radarWarningTexture, app.winWidth - 85, app.winHeight - 85, 180);
leaving = 1;
}
2015-10-20 13:51:49 +02:00
if (leaving && battle.stats[STAT_TIME] % FPS < 40)
{
2018-12-13 08:59:31 +01:00
drawText(app.winWidth / 2, app.winHeight - 30, 14, TA_CENTER, colors.white, CAUTION_TEXT);
}
2015-10-20 13:51:49 +02:00
}