From 12247026c5c2e69464ae54ae3a5156fcc725d4b3 Mon Sep 17 00:00:00 2001 From: XaviDCR92 Date: Sun, 28 May 2017 22:57:01 +0200 Subject: [PATCH] * Takeoff procedure implemented almost completely. TODO: "Holding" message. * Initial implementation to show passengers left when entering correct sequence. --- Levels/LEVEL1.PLT | 9 +- Source/Aircraft.c | 200 ++++++++++++-------- Source/Game.c | 354 +++++++++++++++++++++++++---------- Source/Game.h | 3 +- Source/GameGui.c | 41 +++- Source/GameStructures.h | 2 + Source/Global_Inc.h | 1 + cdimg/DATA/LEVELS/LEVEL1.PLT | 9 +- 8 files changed, 427 insertions(+), 192 deletions(-) diff --git a/Levels/LEVEL1.PLT b/Levels/LEVEL1.PLT index 38ef67e..3b7d6fc 100644 --- a/Levels/LEVEL1.PLT +++ b/Levels/LEVEL1.PLT @@ -6,7 +6,8 @@ #For example: 14:55 #Aircraft arrival (or departure) must be set relative to initial time, in HH:MM format. -ARRIVAL;PHX1002;40;00:05;0;60 -ARRIVAL;PHX1802;40;00:15;0;60 -ARRIVAL;PHX2015;40;00:10;0;60 -DEPARTURE;PHX1000;100;00:05;19;180 +ARRIVAL;PHX1002;40;00:05;0;120 +ARRIVAL;PHX1802;100;01:00;0;120 +ARRIVAL;PHX2015;250;00:10;0;120 +DEPARTURE;PHX1000;100;00:05;19;120 +DEPARTURE;PHX1280;100;00:30;19;120 diff --git a/Source/Aircraft.c b/Source/Aircraft.c index 088167b..7ccc1e2 100644 --- a/Source/Aircraft.c +++ b/Source/Aircraft.c @@ -30,7 +30,7 @@ enum typedef enum t_aircraftSpeeds { AIRCRAFT_SPEED_IDLE = 0, - AIRCRAFT_SPEED_TAXIING, + AIRCRAFT_SPEED_GROUND, AIRCRAFT_SPEED_APPROACH, AIRCRAFT_SPEED_TAKEOFF, AIRCRAFT_SPEED_FINAL, @@ -49,7 +49,7 @@ static TYPE_CARTESIAN_POS AircraftCenterPos; static char * AircraftLiveryNamesTable[] = {"PHX", NULL}; static AIRCRAFT_LIVERY AircraftLiveryTable[] = {AIRCRAFT_LIVERY_0, AIRCRAFT_LIVERY_UNKNOWN}; static const fix16_t AircraftSpeedsTable[] = { [AIRCRAFT_SPEED_IDLE] = 0, - [AIRCRAFT_SPEED_TAXIING] = 0x6666, + [AIRCRAFT_SPEED_GROUND] = 0x6666, [AIRCRAFT_SPEED_TAKEOFF] = 0x20000, [AIRCRAFT_SPEED_FINAL] = 0x10000, [AIRCRAFT_SPEED_FINAL_Z] = 0x4000 }; @@ -192,7 +192,6 @@ bool AircraftRemove(uint8_t aircraftIdx) if(ptrAircraft->FlightDataIdx == aircraftIdx) { - memset(ptrAircraft, 0, sizeof(TYPE_AIRCRAFT_DATA)); ptrAircraft->State = STATE_IDLE; return true; } @@ -213,7 +212,7 @@ void AircraftHandler(void) { continue; } - + AircraftDirection(ptrAircraft); AircraftAttitude(ptrAircraft); AircraftSpeed(ptrAircraft); @@ -231,13 +230,17 @@ void AircraftSpeed(TYPE_AIRCRAFT_DATA* ptrAircraft) break; case STATE_TAKEOFF: + // Fall through + case STATE_CLIMBING: ptrAircraft->Speed = AircraftSpeedsTable[AIRCRAFT_SPEED_TAKEOFF]; break; case STATE_TAXIING: // Fall through + case STATE_HOLDING_RWY: + // Fall through case STATE_READY_FOR_TAKEOFF: - ptrAircraft->Speed = AircraftSpeedsTable[AIRCRAFT_SPEED_TAXIING]; + ptrAircraft->Speed = AircraftSpeedsTable[AIRCRAFT_SPEED_GROUND]; break; case STATE_UNBOARDING: @@ -290,89 +293,127 @@ void AircraftDirection(TYPE_AIRCRAFT_DATA* ptrAircraft) { TYPE_ISOMETRIC_FIX16_POS targetPos; - if(ptrAircraft->Target[ptrAircraft->TargetIdx] == 0) + if(ptrAircraft->State != STATE_CLIMBING) { - return; - } - - targetPos.x = GameGetXFromTile(ptrAircraft->Target[ptrAircraft->TargetIdx]); - targetPos.y = GameGetYFromTile(ptrAircraft->Target[ptrAircraft->TargetIdx]); - targetPos.z = 0; - - ptrAircraft->TargetReached = false; - - if(targetPos.y == ptrAircraft->IsoPos.y) - { - if(targetPos.x > ptrAircraft->IsoPos.x) + if(ptrAircraft->Target[ptrAircraft->TargetIdx] == 0) { - if(targetPos.x <= (ptrAircraft->IsoPos.x + ptrAircraft->Speed) ) + return; + } + + targetPos.x = GameGetXFromTile(ptrAircraft->Target[ptrAircraft->TargetIdx]); + targetPos.y = GameGetYFromTile(ptrAircraft->Target[ptrAircraft->TargetIdx]); + targetPos.z = 0; + + ptrAircraft->TargetReached = false; + + if(targetPos.y == ptrAircraft->IsoPos.y) + { + if(targetPos.x > ptrAircraft->IsoPos.x) { - ptrAircraft->TargetReached = true; + if(targetPos.x <= (ptrAircraft->IsoPos.x + ptrAircraft->Speed) ) + { + ptrAircraft->TargetReached = true; + } + else + { + ptrAircraft->Direction = AIRCRAFT_DIR_EAST; + ptrAircraft->IsoPos.x += ptrAircraft->Speed; + } + } + else if(targetPos.x < ptrAircraft->IsoPos.x) + { + if(targetPos.x >= (ptrAircraft->IsoPos.x - ptrAircraft->Speed) ) + { + ptrAircraft->TargetReached = true; + } + else + { + ptrAircraft->Direction = AIRCRAFT_DIR_WEST; + ptrAircraft->IsoPos.x -= ptrAircraft->Speed; + } } else { - ptrAircraft->Direction = AIRCRAFT_DIR_EAST; + ptrAircraft->TargetReached = true; + } + } + else if(targetPos.x == ptrAircraft->IsoPos.x) + { + if(targetPos.y > ptrAircraft->IsoPos.y) + { + if(targetPos.y <= (ptrAircraft->IsoPos.y + ptrAircraft->Speed) ) + { + ptrAircraft->TargetReached = true; + } + else + { + ptrAircraft->Direction = AIRCRAFT_DIR_SOUTH; + ptrAircraft->IsoPos.y += ptrAircraft->Speed; + } + } + else if(targetPos.y < ptrAircraft->IsoPos.y) + { + if(targetPos.y >= (ptrAircraft->IsoPos.y - ptrAircraft->Speed) ) + { + ptrAircraft->TargetReached = true; + } + else + { + ptrAircraft->Direction = AIRCRAFT_DIR_NORTH; + ptrAircraft->IsoPos.y -= ptrAircraft->Speed; + } + } + else + { + ptrAircraft->TargetReached = true; + } + } + + if(ptrAircraft->TargetReached == true) + { + ptrAircraft->IsoPos.x = targetPos.x; + ptrAircraft->IsoPos.y = targetPos.y; + + if(ptrAircraft->Target[++ptrAircraft->TargetIdx] == 0) + { + dprintf("All targets reached!\n"); + ptrAircraft->State = GameTargetsReached(ptrAircraft->Target[0], ptrAircraft->FlightDataIdx); + } + } + } + else + { + // STATE_CLIMBING + switch(ptrAircraft->Direction) + { + case AIRCRAFT_DIR_EAST: ptrAircraft->IsoPos.x += ptrAircraft->Speed; - } - } - else if(targetPos.x < ptrAircraft->IsoPos.x) - { - if(targetPos.x >= (ptrAircraft->IsoPos.x - ptrAircraft->Speed) ) - { - ptrAircraft->TargetReached = true; - } - else - { - ptrAircraft->Direction = AIRCRAFT_DIR_WEST; - ptrAircraft->IsoPos.x -= ptrAircraft->Speed; - } - } - else - { - ptrAircraft->TargetReached = true; - } - } - else if(targetPos.x == ptrAircraft->IsoPos.x) - { - if(targetPos.y > ptrAircraft->IsoPos.y) - { - if(targetPos.y <= (ptrAircraft->IsoPos.y + ptrAircraft->Speed) ) - { - ptrAircraft->TargetReached = true; - } - else - { - ptrAircraft->Direction = AIRCRAFT_DIR_SOUTH; - ptrAircraft->IsoPos.y += ptrAircraft->Speed; - } - } - else if(targetPos.y < ptrAircraft->IsoPos.y) - { - if(targetPos.y >= (ptrAircraft->IsoPos.y - ptrAircraft->Speed) ) - { - ptrAircraft->TargetReached = true; - } - else - { - ptrAircraft->Direction = AIRCRAFT_DIR_NORTH; - ptrAircraft->IsoPos.y -= ptrAircraft->Speed; - } - } - else - { - ptrAircraft->TargetReached = true; - } - } + break; - if(ptrAircraft->TargetReached == true) - { - ptrAircraft->IsoPos.x = targetPos.x; - ptrAircraft->IsoPos.y = targetPos.y; - - if(ptrAircraft->Target[++ptrAircraft->TargetIdx] == 0) + case AIRCRAFT_DIR_WEST: + ptrAircraft->IsoPos.x -= ptrAircraft->Speed; + break; + + case AIRCRAFT_DIR_NORTH: + ptrAircraft->IsoPos.y -= ptrAircraft->Speed; + break; + + case AIRCRAFT_DIR_SOUTH: + ptrAircraft->IsoPos.y += ptrAircraft->Speed; + break; + + case AIRCRAFT_DIR_NO_DIRECTION: + // Fall through + default: + return; + } + + ptrAircraft->IsoPos.z += AircraftSpeedsTable[AIRCRAFT_SPEED_FINAL_Z]; + + if(GameInsideLevelFromIsoPos(&ptrAircraft->IsoPos) == true) { - dprintf("All targets reached!\n"); - ptrAircraft->State = GameTargetsReached(ptrAircraft->Target[0], ptrAircraft->FlightDataIdx); + dprintf("Flight %d removed\n", ptrAircraft->FlightDataIdx); + GameRemoveFlight(ptrAircraft->FlightDataIdx); } } } @@ -453,6 +494,7 @@ TYPE_ISOMETRIC_POS AircraftGetIsoPos(uint8_t FlightDataIdx) void AircraftAddTargets(TYPE_AIRCRAFT_DATA* ptrAircraft, uint16_t* targets) { memcpy(ptrAircraft->Target, targets, sizeof(uint16_t) * AIRCRAFT_MAX_TARGETS); + ptrAircraft->TargetIdx = 0; } uint16_t AircraftGetTileFromFlightDataIndex(uint8_t index) diff --git a/Source/Game.c b/Source/Game.c index d13598e..ff5bf6e 100644 --- a/Source/Game.c +++ b/Source/Game.c @@ -29,6 +29,14 @@ * Structs and enums * * *************************************/ +typedef struct t_rwyentrydata +{ + AIRCRAFT_DIRECTION Direction; + uint16_t rwyEntryTile; + int8_t rwyStep; + uint16_t rwyHeader; +}TYPE_RWY_ENTRY_DATA; + enum { TILE_GRASS = 0, @@ -136,6 +144,7 @@ static void GameDrawMouse(TYPE_PLAYER* ptrPlayer); static void GameStateUnboarding(TYPE_PLAYER* ptrPlayer, TYPE_FLIGHT_DATA* ptrFlightData); static void GameGenerateUnboardingSequence(TYPE_PLAYER* ptrPlayer); static void GameCreateTakeoffWaypoints(TYPE_PLAYER* ptrPlayer, TYPE_FLIGHT_DATA* ptrFlightData, uint8_t aircraftIdx); +static void GameGetRunwayEntryTile(uint8_t aircraftIdx, TYPE_RWY_ENTRY_DATA* ptrRwyEntry); /* ************************************* * Global Variables @@ -1298,8 +1307,9 @@ void GameStateSelectRunway(TYPE_PLAYER* ptrPlayer, TYPE_FLIGHT_DATA * ptrFlightD else if(ptrPlayer->PadKeySinglePress_Callback(PAD_CROSS) == true) { ptrPlayer->SelectRunway = false; - - dprintf("ptrPlayer->SelectedRunway = %d\n", GameRwy[ptrPlayer->SelectedRunway]); + + DEBUG_PRINT_VAR(GameRwy[ptrPlayer->SelectedRunway]); + if(SystemContains_u16(GameRwy[ptrPlayer->SelectedRunway], GameUsedRwy, GAME_MAX_RUNWAYS) == false) { ptrPlayer->SelectRunway = false; @@ -1326,18 +1336,24 @@ void GameStateSelectRunway(TYPE_PLAYER* ptrPlayer, TYPE_FLIGHT_DATA * ptrFlightD } else if(ptrPlayer->PadKeySinglePress_Callback(PAD_LEFT) == true) { - if(ptrPlayer->SelectedRunway != 0) + if(ptrFlightData->State[ptrPlayer->FlightDataSelectedAircraft] == STATE_APPROACH) { - ptrPlayer->SelectedRunway--; + if(ptrPlayer->SelectedRunway != 0) + { + ptrPlayer->SelectedRunway--; + } } } else if(ptrPlayer->PadKeySinglePress_Callback(PAD_RIGHT) == true) { - if(ptrPlayer->SelectedRunway < (GAME_MAX_RUNWAYS - 1)) + if(ptrFlightData->State[ptrPlayer->FlightDataSelectedAircraft] == STATE_APPROACH) { - if(GameRwy[ptrPlayer->SelectedRunway + 1] != 0) + if(ptrPlayer->SelectedRunway < (GAME_MAX_RUNWAYS - 1)) { - ptrPlayer->SelectedRunway++; + if(GameRwy[ptrPlayer->SelectedRunway + 1] != 0) + { + ptrPlayer->SelectedRunway++; + } } } } @@ -1393,13 +1409,13 @@ void GameSelectAircraftFromList(TYPE_PLAYER* ptrPlayer, TYPE_FLIGHT_DATA * ptrFl case STATE_APPROACH: ptrPlayer->SelectRunway = true; break; - + case STATE_PARKED: ptrPlayer->SelectTaxiwayRunway = true; // Move camera to selected aircraft and add first waypoint. GameSelectAircraftWaypoint(ptrPlayer); break; - + case STATE_LANDED: ptrPlayer->SelectTaxiwayParking = true; // Move camera to selected aircraft and add first waypoint. @@ -1418,6 +1434,26 @@ void GameSelectAircraftFromList(TYPE_PLAYER* ptrPlayer, TYPE_FLIGHT_DATA * ptrFl ptrFlightData->State[AircraftIdx] = STATE_TAKEOFF; GameCreateTakeoffWaypoints(ptrPlayer, ptrFlightData, AircraftIdx); break; + + case STATE_HOLDING_RWY: + { + TYPE_RWY_ENTRY_DATA rwyEntryData = {0}; + uint8_t i; + + ptrPlayer->SelectRunway = true; + GameGetRunwayEntryTile(AircraftIdx, &rwyEntryData); + + for(i = 0; GameRwy[i] != 0 && (i < (sizeof(GameRwy) / sizeof(GameRwy[0]))); i++) + { + if(GameRwy[i] == rwyEntryData.rwyHeader) + { + break; + } + } + + ptrPlayer->SelectedRunway = i; + } + break; default: dprintf("Incompatible state %d!\n",aircraftState); @@ -1517,10 +1553,8 @@ void GameAssignRunwaytoAircraft(TYPE_PLAYER* ptrPlayer, TYPE_FLIGHT_DATA * ptrFl uint8_t aircraftIndex = ptrPlayer->FlightDataSelectedAircraft; uint16_t rwyExit; uint32_t i; - uint16_t targets[AIRCRAFT_MAX_TARGETS]; - uint8_t rwyTiles[GAME_MAX_RWY_LENGTH]; - - memset(targets, 0, sizeof(uint16_t) * AIRCRAFT_MAX_TARGETS); + uint16_t targets[AIRCRAFT_MAX_TARGETS] = {0}; + uint8_t rwyTiles[GAME_MAX_RWY_LENGTH] = {0}; // Remember that ptrPlayer->SelectedAircraft contains an index to // be used with ptrFlightData. @@ -1577,37 +1611,44 @@ void GameAssignRunwaytoAircraft(TYPE_PLAYER* ptrPlayer, TYPE_FLIGHT_DATA * ptrFl return; } } - else if(ptrFlightData->State[aircraftIndex] == STATE_READY_FOR_TAKEOFF) + else if(ptrFlightData->State[aircraftIndex] == STATE_HOLDING_RWY) { - AIRCRAFT_DIRECTION aircraftDir = AircraftGetDirection(AircraftFromFlightDataIndex(aircraftIndex)); - uint16_t rwyTile = 0; + TYPE_RWY_ENTRY_DATA rwyEntryData; + uint8_t i; - switch(aircraftDir) + GameGetRunwayEntryTile(aircraftIndex, &rwyEntryData); + + targets[0] = rwyEntryData.rwyEntryTile; + targets[1] = targets[0] + rwyEntryData.rwyStep; + + dprintf("Added the following targets = "); + + for(i = 0; i < (sizeof(targets) / sizeof(targets[0])); i++) { - case AIRCRAFT_DIR_EAST: - rwyTile = AircraftGetTileFromFlightDataIndex(aircraftIndex) - GameLevelColumns; - break; - - case AIRCRAFT_DIR_WEST: - rwyTile = AircraftGetTileFromFlightDataIndex(aircraftIndex) + GameLevelColumns; - break; - - case AIRCRAFT_DIR_NORTH: - rwyTile = AircraftGetTileFromFlightDataIndex(aircraftIndex) + 1; - break; - - case AIRCRAFT_DIR_SOUTH: - rwyTile = AircraftGetTileFromFlightDataIndex(aircraftIndex) - 1; - break; - - case AIRCRAFT_DIR_NO_DIRECTION: - // Fall through - default: - break; - + dprintf("%d ", targets[i]); } - ptrFlightData->State[aircraftIndex] = STATE_TAKEOFF; - GameScore += SCORE_REWARD_TAKEOFF; + + dprintf("\n"); + + AircraftAddTargets(AircraftFromFlightDataIndex(aircraftIndex), targets); + + /*uint16_t i; + + + i = rwyEntryData.rwyEntryTile; + + DEBUG_PRINT_VAR(rwyEntryData.rwyEntryTile); + DEBUG_PRINT_VAR(rwyEntryData.rwyStep); + + while(GameLevelBuffer[i] != TILE_RWY_START_1) + { + if(i > rwyEntryData.rwyStep) + { + i -= rwyEntryData.rwyStep; + } + } + + GameGetSelectedRunwayArray(i);*/ } } @@ -1682,6 +1723,10 @@ FL_STATE GameTargetsReached(uint16_t firstTarget, uint8_t index) case STATE_TAKEOFF: FlightData.State[index] = STATE_CLIMBING; break; + + case STATE_HOLDING_RWY: + FlightData.State[index] = STATE_READY_FOR_TAKEOFF; + break; default: break; @@ -2055,26 +2100,14 @@ void GameStateUnboarding(TYPE_PLAYER* ptrPlayer, TYPE_FLIGHT_DATA* ptrFlightData ptrFlightData->Passengers[ptrPlayer->FlightDataSelectedAircraft] -= UNBOARDING_PASSENGERS_PER_SEQUENCE; GameScore += SCORE_REWARD_UNLOADING; + ptrPlayer->PassengersLeftSelectedAircraft = ptrFlightData->Passengers[ptrPlayer->FlightDataSelectedAircraft]; + GameGenerateUnboardingSequence(ptrPlayer); } else { // Flight has finished. Remove aircraft and set finished flag - - ptrFlightData->Passengers[ptrPlayer->FlightDataSelectedAircraft] = 0; - ptrFlightData->State[ptrPlayer->FlightDataSelectedAircraft] = STATE_IDLE; - ptrPlayer->Unboarding = false; - ptrFlightData->Finished[ptrPlayer->FlightDataSelectedAircraft] = true; - - if(AircraftRemove(ptrPlayer->FlightDataSelectedAircraft) == false) - { - dprintf("Something went wrong when removing aircraft!\n"); - } - - ptrPlayer->LockTarget = false; - ptrPlayer->LockedAircraft = 0; - - GameScore += SCORE_REWARD_FINISH_FLIGHT; + GameRemoveFlight(ptrPlayer->FlightDataSelectedAircraft); } ptrPlayer->UnboardingSequenceIdx = 0; @@ -2116,85 +2149,200 @@ void GameGenerateUnboardingSequence(TYPE_PLAYER* ptrPlayer) void GameCreateTakeoffWaypoints(TYPE_PLAYER* ptrPlayer, TYPE_FLIGHT_DATA* ptrFlightData, uint8_t aircraftIdx) { // Look for aircraft direction by searching TILE_RWY_EXIT - AIRCRAFT_DIRECTION aircraftDir = AIRCRAFT_DIR_NO_DIRECTION; - uint16_t currentTile = AircraftGetTileFromFlightDataIndex(aircraftIdx); + //uint16_t currentTile = AircraftGetTileFromFlightDataIndex(aircraftIdx); + //uint8_t targetsIdx = 0; + AIRCRAFT_DIRECTION aircraftDir = AircraftGetDirection(AircraftFromFlightDataIndex(aircraftIdx)); + int8_t rwyStep = 0; + uint16_t currentTile = 0; uint16_t targets[AIRCRAFT_MAX_TARGETS] = {0}; - uint8_t targetsIdx = 0; - uint16_t runwayTile = 0; + uint8_t i; + + switch(aircraftDir) + { + case AIRCRAFT_DIR_EAST: + dprintf("EAST\n"); + rwyStep = 1; + break; + + case AIRCRAFT_DIR_WEST: + dprintf("WEST\n"); + rwyStep = -1; + break; + + case AIRCRAFT_DIR_NORTH: + dprintf("NORTH\n"); + rwyStep = -GameLevelColumns; + break; + + case AIRCRAFT_DIR_SOUTH: + dprintf("SOUTH\n"); + rwyStep = GameLevelColumns; + break; + + default: + return; + } + + for(currentTile = (AircraftGetTileFromFlightDataIndex(aircraftIdx) + rwyStep); + (GameLevelBuffer[currentTile] != TILE_RWY_START_1) + && + (GameLevelBuffer[currentTile] != TILE_RWY_START_2); + currentTile -= rwyStep ) + { + + } + + DEBUG_PRINT_VAR(currentTile); + + for(i = 0; i < GAME_MAX_RUNWAYS; i++) + { + if(GameUsedRwy[i] == currentTile) + { + GameUsedRwy[i] = 0; + break; + } + } + + for(currentTile = (AircraftGetTileFromFlightDataIndex(aircraftIdx) + rwyStep); + GameLevelBuffer[currentTile] != TILE_RWY_EXIT; + currentTile += rwyStep ) + { + + } + + targets[0] = currentTile; + + AircraftAddTargets(AircraftFromFlightDataIndex(aircraftIdx), targets); +} + +void GameGetRunwayEntryTile(uint8_t aircraftIdx, TYPE_RWY_ENTRY_DATA* ptrRwyEntry) +{ + // Look for aircraft direction by searching TILE_RWY_EXIT + uint16_t currentTile = AircraftGetTileFromFlightDataIndex(aircraftIdx); + int16_t step = 0; uint16_t i; if( (currentTile > GameLevelColumns) && ( (currentTile + GameLevelColumns) < (sizeof(GameLevelBuffer) / sizeof(GameLevelBuffer[0]) ) ) ) { if(GameLevelBuffer[currentTile + 1] == TILE_RWY_EXIT) { - aircraftDir = AIRCRAFT_DIR_EAST; - runwayTile = currentTile + 1; + ptrRwyEntry->Direction = AIRCRAFT_DIR_EAST; + ptrRwyEntry->rwyStep = GameLevelColumns; + step = -1; } else if(GameLevelBuffer[currentTile - 1] == TILE_RWY_EXIT) { - aircraftDir = AIRCRAFT_DIR_WEST; - runwayTile = currentTile - 1; + ptrRwyEntry->Direction = AIRCRAFT_DIR_WEST; + ptrRwyEntry->rwyStep = -GameLevelColumns; + step = 1; } else if(GameLevelBuffer[currentTile + GameLevelColumns] == TILE_RWY_EXIT) { - aircraftDir = AIRCRAFT_DIR_SOUTH; - runwayTile = currentTile + GameLevelColumns; + ptrRwyEntry->Direction = AIRCRAFT_DIR_SOUTH; + ptrRwyEntry->rwyStep = 1; + step = GameLevelColumns; } else if(GameLevelBuffer[currentTile - GameLevelColumns] == TILE_RWY_EXIT) { - aircraftDir = AIRCRAFT_DIR_NORTH; - runwayTile = currentTile - GameLevelColumns; + ptrRwyEntry->Direction = AIRCRAFT_DIR_NORTH; + ptrRwyEntry->rwyStep = -1; + step = -GameLevelColumns; } else { + ptrRwyEntry->rwyEntryTile = 0; + ptrRwyEntry->Direction = AIRCRAFT_DIR_NO_DIRECTION; + ptrRwyEntry->rwyStep = 0; dprintf("GameCreateTakeoffWaypoints(): could not determine aircraft direction.\n"); return; } - targets[targetsIdx++] = runwayTile; + ptrRwyEntry->rwyEntryTile = currentTile + step; - dprintf("Direction = "); + i = ptrRwyEntry->rwyEntryTile; - switch(aircraftDir) + while( (i > ptrRwyEntry->rwyStep) + && + (i < (GameLevelSize - ptrRwyEntry->rwyStep) ) + && + (GameLevelBuffer[i] != TILE_RWY_START_1) + && + (GameLevelBuffer[i] != TILE_RWY_START_2) ) { - case AIRCRAFT_DIR_EAST: - dprintf("EAST\n"); - break; - - case AIRCRAFT_DIR_WEST: - dprintf("WEST\n"); - break; - - case AIRCRAFT_DIR_NORTH: - dprintf("NORTH\n"); - break; - - case AIRCRAFT_DIR_SOUTH: - dprintf("SOUTH\n"); - for(i = (runwayTile + 1); (i < (runwayTile + GameLevelColumns)) && GameLevelBuffer[i] != TILE_RWY_EXIT; i++) - { - targets[targetsIdx++] = i; - } - break; - - default: - break; + i -= ptrRwyEntry->rwyStep; } - dprintf("Waypoints for takeoff added = "); - - for(i = 0; i < AIRCRAFT_MAX_TARGETS; i++) - { - dprintf("%d ", targets[i]); - } - - dprintf("\n"); - - AircraftAddTargets(AircraftFromFlightDataIndex(aircraftIdx), targets); - + ptrRwyEntry->rwyHeader = i; } else { dprintf("GameCreateTakeoffWaypoints(): Invalid index for tile.\n"); } } + +bool GameInsideLevelFromIsoPos(TYPE_ISOMETRIC_FIX16_POS* ptrIsoPos) +{ + short x = (short)fix16_to_int(ptrIsoPos->x); + short y = (short)fix16_to_int(ptrIsoPos->y); + + if(x < 0) + { + return true; + } + + if(x > (GameLevelColumns << TILE_SIZE_BIT_SHIFT)) + { + return true; + } + + if(y < 0) + { + return true; + } + + if(y > (GameLevelColumns << TILE_SIZE_BIT_SHIFT) ) + { + return true; + } + + return false; +} + +void GameRemoveFlight(uint8_t idx) +{ + TYPE_PLAYER* ptrPlayer; + uint8_t i; + uint8_t j; + + for(i = 0; i < MAX_PLAYERS; i++) + { + ptrPlayer = &PlayerData[i]; + + for(j = 0; j < GAME_MAX_AIRCRAFT; j++) + { + if(ptrPlayer->ActiveAircraftList[j] == idx) + { + ptrPlayer->Unboarding = false; + /*DEBUG_PRINT_VAR(ptrPlayer); + DEBUG_PRINT_VAR(&PlayerData[PLAYER_ONE]); + DEBUG_PRINT_VAR(&PlayerData[PLAYER_TWO]);*/ + + FlightData.Passengers[ptrPlayer->FlightDataSelectedAircraft] = 0; + FlightData.State[ptrPlayer->FlightDataSelectedAircraft] = STATE_IDLE; + FlightData.Finished[ptrPlayer->FlightDataSelectedAircraft] = true; + + if(AircraftRemove(idx) == false) + { + dprintf("Something went wrong when removing aircraft!\n"); + } + + ptrPlayer->LockTarget = false; + ptrPlayer->LockedAircraft = 0; + + GameScore += SCORE_REWARD_FINISH_FLIGHT; + + return; + } + } + } +} diff --git a/Source/Game.h b/Source/Game.h index 3a18a47..c5ff605 100644 --- a/Source/Game.h +++ b/Source/Game.h @@ -50,5 +50,6 @@ FL_STATE GameTargetsReached(uint16_t firstTarget, uint8_t index); uint16_t GameGetTileFromIsoPosition(TYPE_ISOMETRIC_POS * IsoPos); FL_STATE GameGetFlightDataStateFromIdx(uint8_t FlightDataIdx); uint32_t GameGetScore(void); - +bool GameInsideLevelFromIsoPos(TYPE_ISOMETRIC_FIX16_POS* ptrIsoPos); +void GameRemoveFlight(uint8_t idx); #endif //__GAME_HEADER__ diff --git a/Source/GameGui.c b/Source/GameGui.c index cff81f8..f9697bb 100644 --- a/Source/GameGui.c +++ b/Source/GameGui.c @@ -238,6 +238,7 @@ enum static void GameGuiPrepareNotificationString(TYPE_FLIGHT_DATA * ptrFlightData, uint8_t offset); static void GameGuiShowAircraftData(TYPE_PLAYER* ptrPlayer, TYPE_FLIGHT_DATA * ptrFlightData); +static void GameGuiClearPassengersLeft(void); /* ************************************** * Local variables * @@ -250,6 +251,8 @@ static GsGPoly4 SelectedAircraftGPoly4; static GsSprite ArrowsSpr; static GsGPoly4 PauseRect; static GsSprite SecondDisplay; +static TYPE_TIMER* ShowAircraftPassengersTimer; +static bool GameGuiClearPassengersLeft_Flag; static char * GameFileList[] = {"cdrom:\\DATA\\SPRITES\\BUBBLE.TIM;1" , "cdrom:\\DATA\\FONTS\\FONT_1.FNT;1" , @@ -296,6 +299,8 @@ void GameGuiInit(void) PauseRect.attribute |= ENABLE_TRANS | TRANS_MODE(0); + ShowAircraftPassengersTimer = SystemCreateTimer(20, true, GameGuiClearPassengersLeft); + slowScore = 0; } @@ -774,6 +779,28 @@ void GameGuiClock(uint8_t hour, uint8_t min) FontPrintText(&RadioFont,CLOCK_X,CLOCK_Y,strClock); } +void GameGuiShowPassengersLeft(TYPE_PLAYER* ptrPlayer) +{ + if(GameGuiClearPassengersLeft_Flag == true) + { + // Reset flag + GameGuiClearPassengersLeft_Flag = false; + ptrPlayer->PassengersLeftSelectedAircraft = 0; + } + + if(ptrPlayer->PassengersLeftSelectedAircraft != 0) + { + if(GameTwoPlayersActive() == true) + { + FontPrintText(&SmallFont, 48, Y_SCREEN_RESOLUTION - 64, "%d left", ptrPlayer->PassengersLeftSelectedAircraft); + } + else + { + FontPrintText(&SmallFont, 128, Y_SCREEN_RESOLUTION - 64, "%d left", ptrPlayer->PassengersLeftSelectedAircraft); + } + } +} + void GameGuiShowAircraftData(TYPE_PLAYER* ptrPlayer, TYPE_FLIGHT_DATA * ptrFlightData) { uint8_t init_flight = ptrPlayer->FlightDataPage * GAME_GUI_AIRCRAFT_DATA_MAX_PAGE; @@ -978,7 +1005,19 @@ void GameGuiDrawUnboardingSequence(TYPE_PLAYER* ptrPlayer) } // TODO: Draw above the plane - GfxDrawButton(128 + (16*i), Y_SCREEN_RESOLUTION - 32, ptrPlayer->UnboardingSequence[i]); + if(GameTwoPlayersActive() == true) + { + GfxDrawButton(48 + (16*i), Y_SCREEN_RESOLUTION - 32, ptrPlayer->UnboardingSequence[i]); + } + else + { + GfxDrawButton(128 + (16*i), Y_SCREEN_RESOLUTION - 32, ptrPlayer->UnboardingSequence[i]); + } } } } + +void GameGuiClearPassengersLeft(void) +{ + GameGuiClearPassengersLeft_Flag = true; +} diff --git a/Source/GameStructures.h b/Source/GameStructures.h index cb4f1d3..34f5697 100644 --- a/Source/GameStructures.h +++ b/Source/GameStructures.h @@ -178,6 +178,8 @@ typedef struct unsigned short UnboardingSequence[GAME_MAX_SEQUENCE_KEYS]; // Index inside UnboardingSequence[] uint8_t UnboardingSequenceIdx; + // Show passengers left + uint8_t PassengersLeftSelectedAircraft; bool (*PadKeyPressed_Callback)(unsigned short); bool (*PadKeyReleased_Callback)(unsigned short); diff --git a/Source/Global_Inc.h b/Source/Global_Inc.h index fd50bb6..68bb032 100644 --- a/Source/Global_Inc.h +++ b/Source/Global_Inc.h @@ -17,6 +17,7 @@ * *************************************/ #define REFRESH_FREQUENCY 50 //50 Hz PAL / 60 Hz NTSC +#define DEBUG_PRINT_VAR(var) dprintf(#var " = %d\n", var); #ifndef bool typedef enum diff --git a/cdimg/DATA/LEVELS/LEVEL1.PLT b/cdimg/DATA/LEVELS/LEVEL1.PLT index 38ef67e..3b7d6fc 100644 --- a/cdimg/DATA/LEVELS/LEVEL1.PLT +++ b/cdimg/DATA/LEVELS/LEVEL1.PLT @@ -6,7 +6,8 @@ #For example: 14:55 #Aircraft arrival (or departure) must be set relative to initial time, in HH:MM format. -ARRIVAL;PHX1002;40;00:05;0;60 -ARRIVAL;PHX1802;40;00:15;0;60 -ARRIVAL;PHX2015;40;00:10;0;60 -DEPARTURE;PHX1000;100;00:05;19;180 +ARRIVAL;PHX1002;40;00:05;0;120 +ARRIVAL;PHX1802;100;01:00;0;120 +ARRIVAL;PHX2015;250;00:10;0;120 +DEPARTURE;PHX1000;100;00:05;19;120 +DEPARTURE;PHX1280;100;00:30;19;120