1 /*****************************************************************************
2  * Copyright (c) 2014-2020 OpenRCT2 developers
3  *
4  * For a complete list of all authors, please refer to contributors.md
5  * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
6  *
7  * OpenRCT2 is licensed under the GNU General Public License version 3.
8  *****************************************************************************/
9 
10 #pragma once
11 
12 #include "../common.h"
13 #include "../scenario/Scenario.h"
14 
15 #include <memory>
16 
17 struct rct_object_entry;
18 
19 struct scenario_highscore_entry
20 {
21     utf8* fileName;
22     utf8* name;
23     money64 company_value;
24     datetime64 timestamp;
25 };
26 
27 enum class ScenarioSource : uint8_t
28 {
29     RCT1,
30     RCT1_AA,
31     RCT1_LL,
32     RCT2,
33     RCT2_WW,
34     RCT2_TT,
35     Real,
36     Other
37 };
38 
39 struct scenario_index_entry
40 {
41     utf8 path[MAX_PATH];
42     uint64_t timestamp;
43 
44     // Category / sequence
45     uint8_t category;
46     ScenarioSource source_game;
47     int16_t source_index;
48     uint16_t sc_id;
49 
50     // Objective
51     uint8_t objective_type;
52     uint8_t objective_arg_1;
53     int64_t objective_arg_2;
54     int16_t objective_arg_3;
55     scenario_highscore_entry* highscore = nullptr;
56 
57     utf8 internal_name[64]; // Untranslated name
58     utf8 name[64];          // Translated name
59     utf8 details[256];
60 };
61 
62 namespace OpenRCT2
63 {
64     struct IPlatformEnvironment;
65 }
66 
67 struct IScenarioRepository
68 {
69     virtual ~IScenarioRepository() = default;
70 
71     /**
72      * Scans the scenario directories and grabs the metadata for all the scenarios.
73      */
74     virtual void Scan(int32_t language) abstract;
75 
76     virtual size_t GetCount() const abstract;
77     virtual const scenario_index_entry* GetByIndex(size_t index) const abstract;
78     virtual const scenario_index_entry* GetByFilename(const utf8* filename) const abstract;
79     /**
80      * Does not return custom scenarios due to the fact that they may have the same name.
81      */
82     virtual const scenario_index_entry* GetByInternalName(const utf8* name) const abstract;
83     virtual const scenario_index_entry* GetByPath(const utf8* path) const abstract;
84 
85     virtual bool TryRecordHighscore(
86         int32_t language, const utf8* scenarioFileName, money64 companyValue, const utf8* name) abstract;
87 };
88 
89 [[nodiscard]] std::unique_ptr<IScenarioRepository> CreateScenarioRepository(
90     const std::shared_ptr<OpenRCT2::IPlatformEnvironment>& env);
91 [[nodiscard]] IScenarioRepository* GetScenarioRepository();
92 
93 void scenario_repository_scan();
94 [[nodiscard]] size_t scenario_repository_get_count();
95 [[nodiscard]] const scenario_index_entry* scenario_repository_get_by_index(size_t index);
96 [[nodiscard]] bool scenario_repository_try_record_highscore(
97     const utf8* scenarioFileName, money64 companyValue, const utf8* name);
98 void scenario_translate(scenario_index_entry* scenarioEntry);
99