From 0d1df70f2d1a08fdb6389391ee59afc5fbc6277a Mon Sep 17 00:00:00 2001 From: XaviDCR92 Date: Fri, 29 Dec 2017 15:07:17 +0100 Subject: * Aircraft.c: invalid XYZ position was calculated if runway direction != EAST. * Aircraft.c: aircraft direction is now set according to runway direction when aircraft is created. * Game.c: TILE_PARKING_2 was not included on AcceptedTiles[]. * Game.c: GameAssignRunwaytoAircraft() was not looking up runway exit/entry points correctly. --- Source/Aircraft.c | 49 ++++++++--- Source/Exe/AIRPORT.elf | Bin 327252 -> 327440 bytes Source/Exe/AIRPORT.iso | Bin 1474560 -> 1474560 bytes Source/Game.c | 170 ++++++++++++++++++++---------------- Source/Game.h | 15 ++++ Source/GameStructures.h | 2 +- Source/MapEditor/MapEditor.pro.user | 2 +- Source/MapEditor/settings.ini | 2 +- 8 files changed, 153 insertions(+), 87 deletions(-) (limited to 'Source') diff --git a/Source/Aircraft.c b/Source/Aircraft.c index 0150405..423eb13 100644 --- a/Source/Aircraft.c +++ b/Source/Aircraft.c @@ -141,16 +141,47 @@ bool AircraftAddNew( TYPE_FLIGHT_DATA* ptrFlightData, if (ptrFlightData->FlightDirection[FlightDataIndex] == ARRIVAL) { - ptrAircraft->IsoPos.x = 0; + RWY_DIR rwyDir = GameGetRunwayDirection(ptrAircraft->Target[0]); + // Calculate direction automatically. - ptrAircraft->IsoPos.y = targets[0] / level_columns; - ptrAircraft->IsoPos.y <<= TILE_SIZE_BIT_SHIFT; - ptrAircraft->IsoPos.y += TILE_SIZE >> 1; // Adjust to tile center - ptrAircraft->IsoPos.y = fix16_from_int(ptrAircraft->IsoPos.y); + switch (rwyDir) + { + case RWY_DIR_EAST: + ptrAircraft->IsoPos.x = 0; + + ptrAircraft->IsoPos.y = targets[0] / level_columns; + ptrAircraft->IsoPos.y <<= TILE_SIZE_BIT_SHIFT; + ptrAircraft->IsoPos.y += TILE_SIZE >> 1; // Adjust to tile center + ptrAircraft->IsoPos.y = fix16_from_int(ptrAircraft->IsoPos.y); + + ptrAircraft->IsoPos.z = targets[0] % level_columns; + ptrAircraft->IsoPos.z <<= TILE_SIZE_BIT_SHIFT - 1; + ptrAircraft->IsoPos.z = fix16_from_int(ptrAircraft->IsoPos.z); + + ptrAircraft->Direction = AIRCRAFT_DIR_EAST; + break; + + case RWY_DIR_SOUTH: + ptrAircraft->IsoPos.x = targets[0] % level_columns; + ptrAircraft->IsoPos.x <<= TILE_SIZE_BIT_SHIFT; + ptrAircraft->IsoPos.x += TILE_SIZE >> 1; // Adjust to tile center + ptrAircraft->IsoPos.x = fix16_from_int(ptrAircraft->IsoPos.x); - ptrAircraft->IsoPos.z = targets[0] % level_columns; - ptrAircraft->IsoPos.z <<= TILE_SIZE_BIT_SHIFT - 1; - ptrAircraft->IsoPos.z = fix16_from_int(ptrAircraft->IsoPos.z); + ptrAircraft->IsoPos.y = 0; + + ptrAircraft->IsoPos.z = targets[0] / level_columns; + ptrAircraft->IsoPos.z <<= TILE_SIZE_BIT_SHIFT - 1; + ptrAircraft->IsoPos.z = fix16_from_int(ptrAircraft->IsoPos.z); + + ptrAircraft->Direction = AIRCRAFT_DIR_SOUTH; + break; + + case RWY_INVALID_DIR: + // Fall through + default: + Serial_printf("Invalid runway direction %d for inbound flight.\n", rwyDir); + return false; + } } else if (ptrFlightData->FlightDirection[FlightDataIndex] == DEPARTURE) { @@ -162,8 +193,6 @@ bool AircraftAddNew( TYPE_FLIGHT_DATA* ptrFlightData, ptrAircraft->State = ptrFlightData->State[FlightDataIndex]; AircraftFlightDataIdx_HashTable[FlightDataIndex] = AircraftIndex; - ptrAircraft->Direction = AIRCRAFT_DIR_NORTH; // Default to north direction - Serial_printf("\nAircraft Data:\n"); Serial_printf("\tTargets:"); diff --git a/Source/Exe/AIRPORT.elf b/Source/Exe/AIRPORT.elf index 2d1766f..3fc6f3d 100644 Binary files a/Source/Exe/AIRPORT.elf and b/Source/Exe/AIRPORT.elf differ diff --git a/Source/Exe/AIRPORT.iso b/Source/Exe/AIRPORT.iso index 13ea58b..7513386 100644 Binary files a/Source/Exe/AIRPORT.iso and b/Source/Exe/AIRPORT.iso differ diff --git a/Source/Game.c b/Source/Game.c index 0870168..42308f3 100644 --- a/Source/Game.c +++ b/Source/Game.c @@ -2186,7 +2186,7 @@ void GameStateSelectTaxiwayParking(TYPE_PLAYER* ptrPlayer, TYPE_FLIGHT_DATA* ptr ptrPlayer->LastWaypointIdx = i; } - target_tile = GameLevelBuffer[ptrPlayer->Waypoints[ptrPlayer->LastWaypointIdx]]; + target_tile = GameLevelBuffer[ptrPlayer->Waypoints[ptrPlayer->LastWaypointIdx]] & ~(TILE_MIRROR_FLAG); Serial_printf("ptrPlayer->LastWaypointIdx = %d\n", ptrPlayer->LastWaypointIdx); @@ -2199,11 +2199,7 @@ void GameStateSelectTaxiwayParking(TYPE_PLAYER* ptrPlayer, TYPE_FLIGHT_DATA* ptr if ( (target_tile == TILE_PARKING) || - (target_tile == (TILE_PARKING | TILE_MIRROR_FLAG)) - || - (target_tile == TILE_PARKING_2) - || - (target_tile == (TILE_PARKING_2 | TILE_MIRROR_FLAG) ) ) + (target_tile == TILE_PARKING_2) ) { // TODO: Assign path to aircraft AircraftFromFlightDataIndexAddTargets(ptrPlayer->FlightDataSelectedAircraft, ptrPlayer->Waypoints); @@ -2226,6 +2222,10 @@ void GameStateSelectTaxiwayParking(TYPE_PLAYER* ptrPlayer, TYPE_FLIGHT_DATA* ptr ptrFlightData->State[ptrPlayer->FlightDataSelectedAircraft] = STATE_TAXIING; GameScore += SCORE_REWARD_TAXIING; } + else + { + Serial_printf("Tile %d cannot be used as end point.\n", target_tile); + } } } } @@ -2491,6 +2491,40 @@ void GameSelectAircraftFromList(TYPE_PLAYER* ptrPlayer, TYPE_FLIGHT_DATA* ptrFli } } +/* ************************************************************************************************** + * + * @name: RWY_DIR GameGetRunwayDirection(uint16_t rwyHeader) + * + * @author: Xavier Del Campo + * + * @brief: + * Depending on runway header, runway direction is returned. + * + * **************************************************************************************************/ +RWY_DIR GameGetRunwayDirection(uint16_t rwyHeader) +{ + switch(GameLevelBuffer[rwyHeader]) + { + case TILE_RWY_START_1: + return RWY_DIR_EAST; + + case TILE_RWY_START_2: + return RWY_DIR_WEST; + + case TILE_RWY_START_1 | TILE_MIRROR_FLAG: + return RWY_DIR_SOUTH; + + case TILE_RWY_START_2 | TILE_MIRROR_FLAG: + return RWY_DIR_NORTH; + + default: + Serial_printf("Unknown direction for tile %d\n",rwyHeader); + break; + } + + return RWY_INVALID_DIR; +} + /* ************************************************************************************************** * * @name: void GameGetSelectedRunwayArray(uint16_t rwyHeader, uint16_t* rwyArray, size_t sz) @@ -2517,27 +2551,18 @@ void GameSelectAircraftFromList(TYPE_PLAYER* ptrPlayer, TYPE_FLIGHT_DATA* ptrFli * @remarks: * * **************************************************************************************************/ - void GameGetSelectedRunwayArray(uint16_t rwyHeader, uint16_t* rwyArray, size_t sz) { - typedef enum t_rwydir - { - RWY_DIR_EAST = 0, - RWY_DIR_WEST, - RWY_DIR_NORTH, - RWY_DIR_SOUTH, - }RWY_DIR; - static uint16_t last_tile = 0; static uint8_t i = 0; static RWY_DIR dir; if (sz != (GAME_MAX_RWY_LENGTH * sizeof(uint16_t) )) { - Serial_printf("GameGetSelectedRunwayArray: size %d is different" - " than expected (%d bytes). Returning...\n", - sz, - (GAME_MAX_RWY_LENGTH * sizeof(uint16_t) ) ); + Serial_printf( "GameGetSelectedRunwayArray: size %d is different" + " than expected (%d bytes). Returning...\n", + sz, + (GAME_MAX_RWY_LENGTH * sizeof(uint16_t) ) ); return; } @@ -2554,39 +2579,24 @@ void GameGetSelectedRunwayArray(uint16_t rwyHeader, uint16_t* rwyArray, size_t s last_tile = rwyHeader; i = 0; - switch(GameLevelBuffer[rwyHeader]) - { - case TILE_RWY_START_1: - dir = RWY_DIR_EAST; - break; - case TILE_RWY_START_2: - dir = RWY_DIR_WEST; - break; - - case TILE_RWY_START_1 | TILE_MIRROR_FLAG: - dir = RWY_DIR_SOUTH; - break; - - case TILE_RWY_START_2 | TILE_MIRROR_FLAG: - dir = RWY_DIR_NORTH; - break; + dir = GameGetRunwayDirection(rwyHeader); - default: - Serial_printf("Unknown direction for tile %d\n",rwyHeader); + if (dir == RWY_INVALID_DIR) + { return; - } + } } else { // Part two: append tiles to array until runway end is found. if ( (GameLevelBuffer[last_tile] == TILE_RWY_START_1) - || - (GameLevelBuffer[last_tile] == TILE_RWY_START_2) - || - (GameLevelBuffer[last_tile] == (TILE_RWY_START_1 | TILE_MIRROR_FLAG) ) - || - (GameLevelBuffer[last_tile] == (TILE_RWY_START_2 | TILE_MIRROR_FLAG) ) ) + || + (GameLevelBuffer[last_tile] == TILE_RWY_START_2) + || + (GameLevelBuffer[last_tile] == (TILE_RWY_START_1 | TILE_MIRROR_FLAG) ) + || + (GameLevelBuffer[last_tile] == (TILE_RWY_START_2 | TILE_MIRROR_FLAG) ) ) { // Runway end found rwyArray[i++] = last_tile; @@ -2604,13 +2614,25 @@ void GameGetSelectedRunwayArray(uint16_t rwyHeader, uint16_t* rwyArray, size_t s { case RWY_DIR_EAST: last_tile++; - break; + break; + case RWY_DIR_WEST: last_tile--; + break; + case RWY_DIR_NORTH: last_tile -= GameLevelColumns; + break; + case RWY_DIR_SOUTH: last_tile += GameLevelColumns; + break; + + case RWY_INVALID_DIR: + // Fall through + default: + Serial_printf("Invalid runway direction.\n"); + return; } GameGetSelectedRunwayArray(0, rwyArray, sz); @@ -2642,8 +2664,8 @@ void GameAssignRunwaytoAircraft(TYPE_PLAYER* ptrPlayer, TYPE_FLIGHT_DATA* ptrFli { uint16_t assignedRwy = GameRwy[ptrPlayer->SelectedRunway]; uint8_t aircraftIndex = ptrPlayer->FlightDataSelectedAircraft; - uint16_t rwyExit; - uint32_t i; + uint16_t rwyExit = 0; + uint8_t i; uint16_t targets[AIRCRAFT_MAX_TARGETS] = {0}; uint8_t rwyTiles[GAME_MAX_RWY_LENGTH] = {0}; @@ -2655,6 +2677,7 @@ void GameAssignRunwaytoAircraft(TYPE_PLAYER* ptrPlayer, TYPE_FLIGHT_DATA* ptrFli if (ptrFlightData->State[aircraftIndex] == STATE_APPROACH) { uint8_t j; + bool firstEntryPointFound = false; uint16_t rwyArray[GAME_MAX_RWY_LENGTH]; // TODO: Algorithm is not correct. If TILE_RWY_EXIT is placed further, @@ -2676,43 +2699,37 @@ void GameAssignRunwaytoAircraft(TYPE_PLAYER* ptrPlayer, TYPE_FLIGHT_DATA* ptrFli dprintf("rwyTiles[%d] = 0x%02X\n", i, rwyTiles[i]); } - for (j = 0; j < (sizeof(rwyExitTiles) / sizeof(rwyExitTiles[0])); j++) + for (i = 0; (i < GAME_MAX_RWY_LENGTH) && (rwyExit == 0); i++) { - i = SystemIndexOf_U8(rwyExitTiles[j], rwyTiles, 0, GAME_MAX_RWY_LENGTH); - DEBUG_PRINT_VAR(i); - - if (i != -1) + for (j = 0; j < (sizeof(rwyExitTiles) / sizeof(rwyExitTiles[0])); j++) { - dprintf("Success!\n"); - uint8_t nextPos = i + 1; - - for (j = 0; j < (sizeof(rwyExitTiles) / sizeof(rwyExitTiles[0])); j++) + if (rwyTiles[i] == rwyExitTiles[j]) { - i = SystemIndexOf_U8(rwyExitTiles[j], rwyTiles, nextPos, GAME_MAX_RWY_LENGTH); - DEBUG_PRINT_VAR(i); - - if (i != -1) + if (firstEntryPointFound == false) { - break; + firstEntryPointFound = true; + } + else + { + rwyExit = rwyArray[i]; } - } - break; + break; + } } } - if (i == -1) - { + if (rwyExit == 0) + { Serial_printf("ERROR: Could not find TILE_RWY_EXIT or TILE_RWY_EXIT_2 for runway header %d.\n", assignedRwy); return; - } - - rwyExit = rwyArray[i]; + } + // Create two new targets for the recently created aircraft. targets[0] = assignedRwy; targets[1] = rwyExit; - if (AircraftAddNew(ptrFlightData, + if (AircraftAddNew( ptrFlightData, aircraftIndex, targets ) == false) { @@ -2725,7 +2742,6 @@ void GameAssignRunwaytoAircraft(TYPE_PLAYER* ptrPlayer, TYPE_FLIGHT_DATA* ptrFli else if (ptrFlightData->State[aircraftIndex] == STATE_HOLDING_RWY) { TYPE_RWY_ENTRY_DATA rwyEntryData; - uint8_t i; GameGetRunwayEntryTile(aircraftIndex, &rwyEntryData); @@ -3143,11 +3159,17 @@ bool GameWaypointCheckExisting(TYPE_PLAYER* ptrPlayer, uint16_t temp_tile) bool GamePathToTile(TYPE_PLAYER* ptrPlayer, TYPE_FLIGHT_DATA* ptrFlightData) { uint8_t AcceptedTiles[] = { TILE_ASPHALT_WITH_BORDERS, - TILE_PARKING, TILE_RWY_MID, - TILE_RWY_EXIT, TILE_TAXIWAY_CORNER_GRASS, - TILE_TAXIWAY_CORNER_GRASS_2, TILE_TAXIWAY_GRASS, + TILE_PARKING, + TILE_RWY_MID, + TILE_RWY_EXIT, + TILE_TAXIWAY_CORNER_GRASS, + TILE_TAXIWAY_CORNER_GRASS_2, + TILE_TAXIWAY_GRASS, TILE_TAXIWAY_INTERSECT_GRASS, - TILE_RWY_HOLDING_POINT, TILE_RWY_HOLDING_POINT_2 }; + TILE_TAXIWAY_4WAY_CROSSING, + TILE_PARKING_2, + TILE_RWY_HOLDING_POINT, + TILE_RWY_HOLDING_POINT_2 }; uint8_t i; uint8_t j; diff --git a/Source/Game.h b/Source/Game.h index d02f6bc..1196193 100644 --- a/Source/Game.h +++ b/Source/Game.h @@ -20,6 +20,19 @@ #define TILE_SIZE_H 48 #define TILE_SIZE_BIT_SHIFT 6 +/* ************************************* + * Structs and enums + * *************************************/ + +typedef enum t_rwydir +{ + RWY_DIR_EAST = 0, + RWY_DIR_WEST, + RWY_DIR_NORTH, + RWY_DIR_SOUTH, + RWY_INVALID_DIR, +}RWY_DIR; + /* ************************************* * Global variables * *************************************/ @@ -48,4 +61,6 @@ void GameCalculateRemainingAircraft(void); void GameAircraftCollision(uint8_t AircraftIdx); void GameStopFlight(uint8_t AicraftIdx); void GameResumeFlightFromAutoStop(uint8_t AircraftIdx); +RWY_DIR GameGetRunwayDirection(uint16_t rwyHeader); + #endif //GAME_HEADER__ diff --git a/Source/GameStructures.h b/Source/GameStructures.h index 5b847e7..82218a0 100644 --- a/Source/GameStructures.h +++ b/Source/GameStructures.h @@ -10,7 +10,7 @@ #define GAME_MAX_PARKING 32 #define GAME_MAX_RWY_LENGTH 16 #define CHEAT_ARRAY_SIZE 16 -#define AIRCRAFT_MAX_TARGETS 32 +#define AIRCRAFT_MAX_TARGETS 48 #define PLAYER_MAX_WAYPOINTS AIRCRAFT_MAX_TARGETS #define GAME_MAX_SEQUENCE_KEYS 12 diff --git a/Source/MapEditor/MapEditor.pro.user b/Source/MapEditor/MapEditor.pro.user index 5393ece..5f8e915 100644 --- a/Source/MapEditor/MapEditor.pro.user +++ b/Source/MapEditor/MapEditor.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/Source/MapEditor/settings.ini b/Source/MapEditor/settings.ini index ca3d2c8..af1583e 100644 --- a/Source/MapEditor/settings.ini +++ b/Source/MapEditor/settings.ini @@ -1,2 +1,2 @@ [app_settings] -last_dir=C:/cygwin/home/Xavier/Airport/Levels/LEVEL1.LVL +last_dir=C:/cygwin/home/Xavier/Airport/Levels/LEVEL2.LVL -- cgit v1.2.3