From e15ebcba9baa7741d82529482674f85cda85d5c6 Mon Sep 17 00:00:00 2001 From: Steve Date: Wed, 20 Jul 2016 07:13:40 +0100 Subject: [PATCH] Tell player to initially face mission target / enemies, so we're not always facing up the screen. --- src/battle/player.c | 63 +++++++++++++++++++++++++++++++++++--------- src/galaxy/mission.c | 2 ++ src/galaxy/mission.h | 1 + 3 files changed, 53 insertions(+), 13 deletions(-) diff --git a/src/battle/player.c b/src/battle/player.c index 7e61100..35b4556 100644 --- a/src/battle/player.c +++ b/src/battle/player.c @@ -120,10 +120,10 @@ static void setPilotName(void) void doPlayer(void) { - rechargeBoostECM(); - self = player; + rechargeBoostECM(); + if (game.currentMission->challengeData.isChallenge) { applyRestrictions(); @@ -492,9 +492,9 @@ static void selectNewPlayer(int dir) static void activateBoost(void) { - self->dx += sin(TO_RAIDANS(self->angle)) * 10; - self->dy += -cos(TO_RAIDANS(self->angle)) * 10; - self->thrust = sqrt((self->dx * self->dx) + (self->dy * self->dy)); + player->dx += sin(TO_RAIDANS(player->angle)) * 10; + player->dy += -cos(TO_RAIDANS(player->angle)) * 10; + player->thrust = sqrt((player->dx * player->dx) + (player->dy * player->dy)); battle.boostTimer = 0; @@ -507,14 +507,14 @@ static void deactivateBoost(void) thrust = -1; - while (thrust != self->thrust) + while (thrust != player->thrust) { - thrust = self->thrust; + thrust = player->thrust; - v = (self->speed / sqrt(self->thrust)); - self->dx = v * self->dx; - self->dy = v * self->dy; - self->thrust = sqrt((self->dx * self->dx) + (self->dy * self->dy)); + v = (player->speed / sqrt(player->thrust)); + player->dx = v * player->dx; + player->dy = v * player->dy; + player->thrust = sqrt((player->dx * player->dx) + (player->dy * player->dy)); } } @@ -575,7 +575,8 @@ static void selectTarget(void) { if (e->active && e != player && (e->flags & EF_TAKES_DAMAGE) && (!(e->flags & EF_NO_PLAYER_TARGET)) && e->side != player->side && e->alive == ALIVE_ALIVE && e->systemPower > 0 && i < MAX_SELECTABLE_TARGETS) { - dist = getDistance(self->x, self->y, e->x, e->y); + dist = getDistance(player->x, player->y, e->x, e->y); + if (dist < closest) { near = e; @@ -629,7 +630,7 @@ static void selectMissionTarget(void) { if (e->active && e->flags & EF_MISSION_TARGET && e->alive == ALIVE_ALIVE) { - dist = getDistance(self->x, self->y, e->x, e->y); + dist = getDistance(player->x, player->y, e->x, e->y); if (battle.missionTarget == NULL) { @@ -674,6 +675,42 @@ static int isPriorityMissionTarget(Entity *e, int dist, int closest) return dist < closest; } +void setInitialPlayerAngle(void) +{ + Entity *e; + + selectMissionTarget(); + + if (battle.missionTarget) + { + player->angle = getAngle(player->x, player->y, battle.missionTarget->x, battle.missionTarget->y); + } + else + { + selectTarget(); + + if (player->target) + { + player->angle = getAngle(player->x, player->y, player->target->x, player->target->y); + } + else + { + if (battle.jumpgate) + { + player->angle = getAngle(player->x, player->y, battle.jumpgate->x, battle.jumpgate->y); + } + } + } + + for (e = battle.entityHead.next ; e != NULL ; e = e->next) + { + if (e->side == player->side) + { + e->angle = player->angle; + } + } +} + static void cycleRadarZoom(void) { battle.radarRange = (battle.radarRange + 1) % 3; diff --git a/src/galaxy/mission.c b/src/galaxy/mission.c index 3662fee..d77424a 100644 --- a/src/galaxy/mission.c +++ b/src/galaxy/mission.c @@ -208,6 +208,8 @@ void loadMission(char *filename) initPlayer(); initMissionInfo(); + + setInitialPlayerAngle(); addAllToQuadtree(); diff --git a/src/galaxy/mission.h b/src/galaxy/mission.h index 4a150ca..6daa8d1 100644 --- a/src/galaxy/mission.h +++ b/src/galaxy/mission.h @@ -63,6 +63,7 @@ extern void activateNextWaypoint(void); extern void awardStatsTrophies(void); extern void awardPostMissionTrophies(void); extern void awardCraftTrophy(void); +extern void setInitialPlayerAngle(void); extern Battle battle; extern Dev dev;