aboutsummaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
authorXaviDCR92 <xavi.dcr@gmail.com>2017-08-19 16:51:00 +0200
committerXaviDCR92 <xavi.dcr@gmail.com>2017-08-19 16:51:00 +0200
commite778deb2c0c7fa2ce2d605dde7a5fe86a686e078 (patch)
tree90684cd779d13b5e490a8289e8770ba999da00e5 /Source
parentb1aad213d450beae9920e30d6534680474f8df6f (diff)
downloadairport-e778deb2c0c7fa2ce2d605dde7a5fe86a686e078.tar.gz
* (Bugfix): ptrPlayer->SelectedAircraft was not being updated correctly when new aircraft appeared.
* (Bugfix): PltParser was casting remaining time to uint8_t instead of uint16_t. * Reduced file buffer size to original value. * GfxDrawButton(): L1/R1/L2/R2 text is now printed on top of Lx/Rx button. * Other minor changes.
Diffstat (limited to 'Source')
-rw-r--r--Source/Game.c94
-rw-r--r--Source/GameGui.c19
-rw-r--r--Source/Gfx.c37
-rw-r--r--Source/Menu.c2
-rw-r--r--Source/PltParser.c46
-rw-r--r--Source/System.c2
6 files changed, 129 insertions, 71 deletions
diff --git a/Source/Game.c b/Source/Game.c
index 3657a31..844f168 100644
--- a/Source/Game.c
+++ b/Source/Game.c
@@ -149,6 +149,7 @@ enum
* *************************************/
static void GameInit(void);
+static bool GameExit(void);
static void GameLoadLevel(void);
static bool GamePause(void);
static void GameFinished(uint8_t i);
@@ -295,26 +296,10 @@ void Game(bool two_players)
while(1)
{
- if(GameFinishedFlag == true)
- {
- // Exit game on level finished.
- if(GameGuiFinishedDialog(&PlayerData[PLAYER_ONE]) == true)
- {
- break;
- }
- }
-
- if(GamePause() == true)
- {
- // Exit game if player desires to exit.
- break;
- }
-
- if(GameAircraftCollisionFlag == true)
- {
- GameGuiAircraftCollision(&PlayerData[PLAYER_ONE]);
- break;
- }
+ if(GameExit() == true)
+ {
+ break;
+ }
GameEmergencyMode();
@@ -331,8 +316,46 @@ void Game(bool two_players)
GfxDisableSplitScreen();
EndAnimation();
-
- SfxPlayTrack(INTRO_TRACK);
+}
+
+/* ***************************************************************************************
+ *
+ * @name: bool GameExit(void)
+ *
+ * @author: Xavier Del Campo
+ *
+ * @brief:
+ * Evaluates special conditions which end current game and return to main menu.
+ *
+ * @returns:
+ * True if game has to be exitted, false otherwise.
+ *
+ * ***************************************************************************************/
+
+bool GameExit(void)
+{
+ if(GameFinishedFlag == true)
+ {
+ // Exit game on level finished.
+ if(GameGuiFinishedDialog(&PlayerData[PLAYER_ONE]) == true)
+ {
+ return true;
+ }
+ }
+
+ if(GamePause() == true)
+ {
+ // Exit game if player desires to exit.
+ return true;
+ }
+
+ if(GameAircraftCollisionFlag == true)
+ {
+ GameGuiAircraftCollision(&PlayerData[PLAYER_ONE]);
+ return true;
+ }
+
+ return false;
}
/* ***************************************************************************************
@@ -856,7 +879,7 @@ void GameCalculations(void)
{
GamePlayerHandler(&PlayerData[i], &FlightData);
}
- }
+ }
}
/* ***************************************************************************************
@@ -886,15 +909,16 @@ void GamePlayerHandler(TYPE_PLAYER* ptrPlayer, TYPE_FLIGHT_DATA* ptrFlightData)
// which use this are currently active.
ptrPlayer->InvalidPath = false; // Do the same thing for "InvalidPath".
- ptrPlayer->FlightDataSelectedAircraft = ptrPlayer->ActiveAircraftList[ptrPlayer->SelectedAircraft];
+ // Recalculate ptrPlayer->SelectedAircraft. In case new aircraft appear, we may be pointing
+ // to a incorrect instance.
+ GameActiveAircraftList(ptrPlayer, ptrFlightData);
if(GameAircraftCollisionFlag == true)
{
TYPE_ISOMETRIC_POS IsoPos = AircraftGetIsoPos(GameAircraftCollisionIdx);
CameraMoveToIsoPos(ptrPlayer, IsoPos);
}
-
- GameActiveAircraftList(ptrPlayer, ptrFlightData);
+
GameStateUnboarding(ptrPlayer, ptrFlightData);
GameStateLockTarget(ptrPlayer, ptrFlightData);
GameStateSelectRunway(ptrPlayer, ptrFlightData);
@@ -1411,8 +1435,6 @@ void GameAircraftState(uint8_t i)
target[0] = FlightData.Parking[i];
Serial_printf("Target assigned = %d\n", target[0]);
-
- Serial_printf("2\n");
if(AircraftAddNew(&FlightData, i, target) == false)
{
@@ -2530,8 +2552,6 @@ void GameAssignRunwaytoAircraft(TYPE_PLAYER* ptrPlayer, TYPE_FLIGHT_DATA* ptrFli
targets[0] = assignedRwy;
targets[1] = rwyExit;
-
- Serial_printf("1\n");
if( AircraftAddNew(ptrFlightData,
aircraftIndex,
@@ -3767,7 +3787,7 @@ void GameActiveAircraftList(TYPE_PLAYER* ptrPlayer, TYPE_FLIGHT_DATA* ptrFlightD
// Clear all pointers for aircraft data first.
// Then, rebuild aircraft list for player.
- lastFlightDataIdx = ptrPlayer->FlightDataSelectedAircraft;
+ lastFlightDataIdx = ptrPlayer->ActiveAircraftList[ptrPlayer->SelectedAircraft];
memset(ptrPlayer->ActiveAircraftList, 0, GAME_MAX_AIRCRAFT);
ptrPlayer->ActiveAircraft = 0;
@@ -3783,7 +3803,7 @@ void GameActiveAircraftList(TYPE_PLAYER* ptrPlayer, TYPE_FLIGHT_DATA* ptrFlightD
}
}
- currentFlightDataIdx = ptrPlayer->FlightDataSelectedAircraft;
+ currentFlightDataIdx = ptrPlayer->ActiveAircraftList[ptrPlayer->SelectedAircraft];
if(GameAircraftCreatedFlag == true)
{
@@ -3791,18 +3811,26 @@ void GameActiveAircraftList(TYPE_PLAYER* ptrPlayer, TYPE_FLIGHT_DATA* ptrFlightD
if(ptrPlayer->ActiveAircraft > 1)
{
+ dprintf("currentFlightDataIdx = %d, lastFlightDataIdx = %d\n",
+ currentFlightDataIdx,
+ lastFlightDataIdx );
if(currentFlightDataIdx != lastFlightDataIdx)
{
for(ptrPlayer->SelectedAircraft = 0; ptrPlayer->SelectedAircraft < FlightData.nAircraft; ptrPlayer->SelectedAircraft++)
{
- if(ptrPlayer->FlightDataSelectedAircraft == lastFlightDataIdx)
+ if(ptrPlayer->ActiveAircraftList[ptrPlayer->SelectedAircraft] == lastFlightDataIdx)
{
+ dprintf("Recalculated ptrPlayer->SelectedAircraft from %d to %d.\n",
+ currentFlightDataIdx,
+ ptrPlayer->SelectedAircraft );
break;
}
}
}
}
}
+
+ ptrPlayer->FlightDataSelectedAircraft = ptrPlayer->ActiveAircraftList[ptrPlayer->SelectedAircraft];
}
/* *******************************************************************************************
diff --git a/Source/GameGui.c b/Source/GameGui.c
index c049ebd..0a0ea72 100644
--- a/Source/GameGui.c
+++ b/Source/GameGui.c
@@ -82,14 +82,6 @@ enum
enum
{
- AIRCRAFT_STOP_X = 192,
- AIRCRAFT_STOP_TEXT_X = AIRCRAFT_STOP_X + 16,
- AIRCRAFT_STOP_Y = AIRCRAFT_LOCK_TARGET_Y,
- AIRCRAFT_STOP_TEXT_Y = AIRCRAFT_STOP_Y + 4
-};
-
-enum
-{
AIRCRAFT_DATA_FLIGHT_GSGPOLY4_R0 = NORMAL_LUMINANCE,
AIRCRAFT_DATA_FLIGHT_GSGPOLY4_R1 = AIRCRAFT_DATA_FLIGHT_GSGPOLY4_R0,
AIRCRAFT_DATA_FLIGHT_GSGPOLY4_R2 = 0,
@@ -412,6 +404,14 @@ void GameGuiAircraftList(TYPE_PLAYER* ptrPlayer, TYPE_FLIGHT_DATA* ptrFlightData
GAME_GUI_REMAINING_AIRCRAFT_X_2PLAYER = AIRCRAFT_DATA_GSGPOLY4_X0_2PLAYER + 16,
GAME_GUI_REMAINING_AIRCRAFT_Y_2PLAYER = AIRCRAFT_DATA_GSGPOLY4_Y2_2PLAYER - 16
};
+
+ enum
+ {
+ AIRCRAFT_STOP_X = 128,
+ AIRCRAFT_STOP_TEXT_X = AIRCRAFT_STOP_X + 32,
+ AIRCRAFT_STOP_Y = AIRCRAFT_LOCK_TARGET_Y,
+ AIRCRAFT_STOP_TEXT_Y = AIRCRAFT_STOP_Y + 4
+ };
if(ptrPlayer->ShowAircraftData == true)
{
@@ -543,7 +543,7 @@ void GameGuiAircraftList(TYPE_PLAYER* ptrPlayer, TYPE_FLIGHT_DATA* ptrFlightData
GsSortGPoly4(&SelectedAircraftGPoly4);
- PageUpDownSpr.attribute |= GFX_1HZ_FLASH;
+ PageUpDownSpr.attribute |= GFX_2HZ_FLASH;
if(ptrPlayer->ActiveAircraft > (GAME_GUI_AIRCRAFT_DATA_MAX_PAGE * (ptrPlayer->FlightDataPage + 1) ) )
{
@@ -609,6 +609,7 @@ void GameGuiAircraftList(TYPE_PLAYER* ptrPlayer, TYPE_FLIGHT_DATA* ptrFlightData
}
else if(ptrFlightData->State[ptrPlayer->FlightDataSelectedAircraft] == STATE_TAXIING)
{
+ GfxDrawButton(AIRCRAFT_STOP_X, AIRCRAFT_STOP_Y, PAD_L1);
FontPrintText(&SmallFont, AIRCRAFT_STOP_TEXT_X, AIRCRAFT_STOP_TEXT_Y, "Stop immediately");
}
}
diff --git a/Source/Gfx.c b/Source/Gfx.c
index 85b36de..8029d14 100644
--- a/Source/Gfx.c
+++ b/Source/Gfx.c
@@ -443,6 +443,12 @@ void GfxButtonRemoveFlags(uint8_t flags)
void GfxDrawButton(short x, short y, unsigned short btn)
{
+ enum
+ {
+ LR_BUTTON_TEXT_OFFSET_X = 4,
+ LR_BUTTON_TEXT_OFFSET_Y = 4
+ };
+
static bool first_entered = true;
static short orig_u;
static short orig_v;
@@ -539,6 +545,37 @@ void GfxDrawButton(short x, short y, unsigned short btn)
GfxSortSprite(&PSXButtons);
+ switch(btn)
+ {
+ case PAD_L1:
+ FontPrintText( &SmallFont,
+ x + LR_BUTTON_TEXT_OFFSET_X,
+ y + LR_BUTTON_TEXT_OFFSET_Y,
+ "L1" );
+ break;
+
+ case PAD_L2:
+ FontPrintText( &SmallFont,
+ x + LR_BUTTON_TEXT_OFFSET_X,
+ y + LR_BUTTON_TEXT_OFFSET_Y,
+ "L2" );
+ break;
+
+ case PAD_R1:
+ FontPrintText( &SmallFont,
+ x + LR_BUTTON_TEXT_OFFSET_X,
+ y + LR_BUTTON_TEXT_OFFSET_Y,
+ "R1" );
+ break;
+
+ case PAD_R2:
+ FontPrintText( &SmallFont,
+ x + LR_BUTTON_TEXT_OFFSET_X,
+ y + LR_BUTTON_TEXT_OFFSET_Y,
+ "R2" );
+ break;
+ }
+
PSXButtons.attribute &= ~H_FLIP;
PSXButtons.rotate = 0;
}
diff --git a/Source/Menu.c b/Source/Menu.c
index 8d5141a..5b47c0b 100644
--- a/Source/Menu.c
+++ b/Source/Menu.c
@@ -369,6 +369,8 @@ void MainMenuRestoreInitValues(void)
MainMenuBtn[TWO_PLAYER_BUTTON_INDEX].timer = 0;
GfxSetGlobalLuminance(NORMAL_LUMINANCE);
+
+ SfxPlayTrack(INTRO_TRACK);
}
void MainMenuButtonHandler(void)
diff --git a/Source/PltParser.c b/Source/PltParser.c
index 8460314..9427494 100644
--- a/Source/PltParser.c
+++ b/Source/PltParser.c
@@ -16,23 +16,6 @@
* Structs and enums *
* *************************************/
-enum
-{
- DEPARTURE_ARRIVAL_INDEX = 0,
- FLIGHT_NUMBER_INDEX,
- PASSENGERS_INDEX,
- HOURS_MINUTES_INDEX,
- PARKING_INDEX,
- REMAINING_TIME_INDEX
-};
-
-enum
-{
- PLT_HOUR_MINUTE_CHARACTERS = 2,
- PLT_FIRST_LINE_CHARACTERS = 5,
- PLT_COLON_POSITION = 2
-};
-
/* *************************************
* Local Variables
* *************************************/
@@ -44,6 +27,23 @@ static void PltParserResetBuffers(TYPE_FLIGHT_DATA* ptrFlightData);
bool PltParserLoadFile(char* strPath, TYPE_FLIGHT_DATA* ptrFlightData)
{
+ enum
+ {
+ DEPARTURE_ARRIVAL_INDEX = 0,
+ FLIGHT_NUMBER_INDEX,
+ PASSENGERS_INDEX,
+ HOURS_MINUTES_INDEX,
+ PARKING_INDEX,
+ REMAINING_TIME_INDEX
+ };
+
+ enum
+ {
+ PLT_HOUR_MINUTE_CHARACTERS = 2,
+ PLT_FIRST_LINE_CHARACTERS = 5,
+ PLT_COLON_POSITION = 2
+ };
+
uint8_t i;
uint8_t j;
uint8_t aircraftIndex;
@@ -136,16 +136,6 @@ bool PltParserLoadFile(char* strPath, TYPE_FLIGHT_DATA* ptrFlightData)
while(lineBufferPtr != NULL)
{
- /*
- * enum
- {
- DEPARTURE_ARRIVAL_INDEX = 0,
- FLIGHT_NUMBER_INDEX,
- PASSENGERS_INDEX,
- HOURS_MINUTES_INDEX,
- PARKING_INDEX,
- REMAINING_TIME_INDEX
- };*/
switch(i)
{
case DEPARTURE_ARRIVAL_INDEX:
@@ -212,7 +202,7 @@ bool PltParserLoadFile(char* strPath, TYPE_FLIGHT_DATA* ptrFlightData)
break;
case REMAINING_TIME_INDEX:
- ptrFlightData->RemainingTime[aircraftIndex] = (uint8_t)atoi(lineBufferPtr);
+ ptrFlightData->RemainingTime[aircraftIndex] = (uint16_t)atoi(lineBufferPtr);
Serial_printf("ptrFlightData->RemainingTime[%d] = %d\n", aircraftIndex, ptrFlightData->RemainingTime[aircraftIndex]);
break;
diff --git a/Source/System.c b/Source/System.c
index c9f94af..7488028 100644
--- a/Source/System.c
+++ b/Source/System.c
@@ -14,7 +14,7 @@
* Defines
* *************************************/
-#define FILE_BUFFER_SIZE 0x4AA60
+#define FILE_BUFFER_SIZE 0x20014
#define END_STACK_PATTERN (uint32_t) 0x18022015
#define BEGIN_STACK_ADDRESS (uint32_t*) 0x801FFF00