1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-17 03:53:07 +01:00

finish conversion of RCT1 import to c++

This commit is contained in:
Ted John
2016-04-17 15:21:35 +01:00
parent cf7b81fd3a
commit 7754204a25
10 changed files with 2143 additions and 907 deletions

View File

@@ -271,6 +271,7 @@
<ClInclude Include="src\platform\platform.h" />
<ClInclude Include="src\rct1.h" />
<ClInclude Include="src\rct1\import.h" />
<ClInclude Include="src\rct1\S4Importer.h" />
<ClInclude Include="src\rct2.h" />
<ClInclude Include="src\ride\cable_lift.h" />
<ClInclude Include="src\ride\ride.h" />

View File

@@ -591,8 +591,8 @@
<ClCompile Include="src\windows\themes.c">
<Filter>Source\Windows</Filter>
</ClCompile>
<ClCompile Include="src\rct1\tables.cpp" />
<ClCompile Include="src\rct1\S4Importer.cpp" />
<ClCompile Include="src\rct1\tables.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\management\award.h">
@@ -905,6 +905,7 @@
<Filter>Source\Core</Filter>
</ClInclude>
<ClInclude Include="src\rct1\import.h" />
<ClInclude Include="src\rct1\S4Importer.h" />
<ClInclude Include="resources\resource.h">
<Filter>Resource Files</Filter>
</ClInclude>

View File

@@ -1,5 +1,6 @@
#pragma once
#include <functional>
#include <vector>
#include "../common.h"
@@ -89,4 +90,17 @@ public:
Guard::ArgumentInRange(index, (size_t)0, this->size() - 1);
return std::vector<T>::operator[](index);
}
size_t IndexOf(std::function<bool(T)> predicate)
{
for (size_t i = 0; i < this->size(); i++)
{
T item = std::vector<T>::operator[](i);
if (predicate(item))
{
return i;
}
}
return SIZE_MAX;
}
};

View File

@@ -33,6 +33,29 @@ namespace Path
return buffer;
}
const utf8 * GetFileName(const utf8 * path)
{
const utf8 * lastPathSeperator = nullptr;
for (const utf8 * ch = path; *ch != '\0'; ch++)
{
if (*ch == platform_get_path_separator())
{
lastPathSeperator = ch;
}
#ifdef _WINDOWS_
// Windows also allows forward slashes in paths
else if (*ch == '/')
{
lastPathSeperator = ch;
}
#endif
}
return lastPathSeperator == nullptr ?
path :
lastPathSeperator + 1;
}
utf8 * GetFileNameWithoutExtension(utf8 * buffer, size_t bufferSize, const utf8 * path)
{
const utf8 * lastDot = nullptr;

View File

@@ -9,6 +9,7 @@ namespace Path
{
utf8 * Append(utf8 * buffer, size_t bufferSize, const utf8 * src);
utf8 * GetDirectory(utf8 * buffer, size_t bufferSize, const utf8 * path);
const utf8 * GetFileName(const utf8 * path);
utf8 * GetFileNameWithoutExtension(utf8 * buffer, size_t bufferSize, const utf8 * path);
utf8 * GetAbsolute(utf8 * buffer, size_t bufferSize, const utf8 * relativePath);
bool Equals(const utf8 * a, const utf8 * b);

View File

@@ -2149,58 +2149,6 @@ static int rct1_get_sc_number(const char *path)
}
}
bool rct1_load_saved_game(const char *path)
{
rct1_s4 *s4;
s4 = malloc(sizeof(rct1_s4));
if (!rct1_read_sv4(path, s4)) {
free(s4);
return false;
}
rct1_import_s4_properly(s4);
free(s4);
game_load_init();
return true;
}
bool rct1_load_scenario(const char *path)
{
rct1_s4 *s4;
s4 = malloc(sizeof(rct1_s4));
if (!rct1_read_sc4(path, s4)) {
free(s4);
return false;
}
rct1_import_s4_properly(s4);
int scNumber = rct1_get_sc_number(path);
if (scNumber != -1) {
rct_s6_info *s6Info = (rct_s6_info*)0x0141F570;
source_desc sourceDesc;
if (scenario_get_source_desc_by_id(scNumber, &sourceDesc)) {
rct_string_id localisedStringIds[3];
if (language_get_localised_scenario_strings(sourceDesc.title, localisedStringIds)) {
if (localisedStringIds[0] != STR_NONE) {
safe_strcpy(s6Info->name, language_get_string(localisedStringIds[0]), 64);
}
if (localisedStringIds[2] != STR_NONE) {
safe_strcpy(s6Info->details, language_get_string(localisedStringIds[2]), 256);
}
}
}
}
free(s4);
scenario_begin();
return true;
}
static void rct1_import_map_elements(rct1_s4 *s4)
{
memcpy(gMapElements, s4->map_elements, 0xC000 * sizeof(rct_map_element));

File diff suppressed because it is too large Load Diff

96
src/rct1/S4Importer.h Normal file
View File

@@ -0,0 +1,96 @@
#pragma once
#include "../common.h"
#include "../core/List.hpp"
extern "C"
{
#include "../rct1.h"
}
/**
* Class to import RollerCoaster Tycoon 1 scenarios (*.SC4) and saved games (*.SV4).
*/
class S4Importer
{
public:
void LoadSavedGame(const utf8 * path);
void LoadScenario(const utf8 * path);
void Import();
private:
const utf8 * _s4Path;
rct1_s4 _s4;
uint8 _gameVersion;
// Lists of dynamic object entries
List<const char *> _rideEntries;
List<const char *> _smallSceneryEntries;
List<const char *> _largeSceneryEntries;
List<const char *> _wallEntries;
List<const char *> _sceneryGroupEntries;
// Lookup tables for converting from RCT1 hard coded types to the new dynamic object entries
uint8 _rideTypeToRideEntryMap[96];
uint8 _vehicleTypeToRideEntryMap[96];
uint8 _smallSceneryTypeToEntryMap[96];
uint8 _largeSceneryTypeToEntryMap[96];
uint8 _wallTypeToEntryMap[96];
uint8 _sceneryThemeTypeToEntryMap[24];
// Research
uint8 _researchRideEntryUsed[128];
uint8 _researchRideTypeUsed[128];
void Initialise();
/**
* Scans the map and research list for all the object types used and builds lists and
* lookup tables for converting from hard coded RCT1 object types to dynamic object entries.
*/
void CreateAvailableObjectMappings();
void AddAvailableEntriesFromResearchList();
void AddAvailableEntriesFromMap();
void AddAvailableEntriesFromRides();
void AddEntryForRideType(uint8 rideType);
void AddEntryForVehicleType(uint8 rideType, uint8 vehicleType);
void AddEntryForSmallScenery(uint8 smallSceneryType);
void AddEntryForLargeScenery(uint8 largeSceneryType);
void AddEntryForWall(uint8 wallType);
void AddEntriesForSceneryTheme(uint8 sceneryThemeType);
void LoadObjects();
void LoadObjects(uint8 objectType, List<const char *> entries);
void ImportMapElements();
void ImportRides();
void ImportRide(rct_ride * dst, rct1_ride * src);
void ImportRideMeasurements();
void ImportRideMeasurement(rct_ride_measurement * dst, rct_ride_measurement * src);
void ImportPeepSpawns();
void ImportMapAnimations();
void ImportFinance();
void ImportResearch();
void InsertResearchVehicle(const rct1_research_item * researchItem, bool researched);
void ImportParkName();
void ImportScenarioNameDetails();
void ImportScenarioObjective();
void ImportSavedView();
void ClearExtraTileEntries();
void FixColours();
void FixZ();
void FixPaths();
void FixWalls();
void ConvertWall(int * type, int * colourA, int * colourB, int * colourC);
void FixBanners();
void ImportBanner(rct_banner * dst, rct_banner * src);
void FixTerrain();
void FixEntrancePositions();
void FixMapElementEntryTypes();
const rct1_research_item * GetResearchList(size_t * count);
int GetSCNumber();
const char * GetUserString(rct_string_id stringId);
};

View File

@@ -2,13 +2,15 @@
namespace RCT1
{
namespace Tables
{
const char * GetRideTypeObject(uint8 rideType);
const char * GetVehicleObject(uint8 vehicleType);
const char * GetSmallSceneryObject(uint8 smallSceneryType);
const char * GetLargeSceneryObject(uint8 largeSceneryType);
const char * GetWallObject(uint8 wallType);
const char * GetSceneryGroupObject(uint8 sceneryGroupType);
}
colour_t GetColour(colour_t colour);
uint8 GetTerrain(uint8 terrain);
uint8 GetTerrainEdge(uint8 terrainEdge);
uint8 GetRideType(uint8 rideType);
const char * GetRideTypeObject(uint8 rideType);
const char * GetVehicleObject(uint8 vehicleType);
const char * GetSmallSceneryObject(uint8 smallSceneryType);
const char * GetLargeSceneryObject(uint8 largeSceneryType);
const char * GetWallObject(uint8 wallType);
const char * GetSceneryGroupObject(uint8 sceneryGroupType);
}

File diff suppressed because it is too large Load Diff