Skip to content

Commit

Permalink
Add English language
Browse files Browse the repository at this point in the history
  • Loading branch information
rbergen authored Oct 12, 2022
2 parents eff9e9e + 8c31dd3 commit 1cf5fc5
Show file tree
Hide file tree
Showing 55 changed files with 1,868 additions and 684 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.15.0)

project(
R136
VERSION 3.3.3)
VERSION 3.4.0)

set(CURSES_NEED_NCURSES 1)
set(CURSES_NEED_WIDE 1)
Expand Down
3 changes: 2 additions & 1 deletion R136.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<None Include="cpp.hint" />
<None Include="README.md" />
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -212,7 +213,7 @@
<ClCompile Include="src\commands\simple.cpp" />
<ClCompile Include="src\console.cpp" />
<ClCompile Include="src\general.cpp" />
<ClCompile Include="src\init.cpp" />
<ClCompile Include="src\startup.cpp" />
<ClCompile Include="src\intro.cpp" />
<ClCompile Include="src\items\bandage.cpp" />
<ClCompile Include="src\items\flashlight.cpp" />
Expand Down
5 changes: 3 additions & 2 deletions R136.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
</ItemGroup>
<ItemGroup>
<None Include="README.md" />
<None Include="cpp.hint" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="include\base.h">
Expand Down Expand Up @@ -111,14 +112,14 @@
<Filter>Header Files\inlines</Filter>
</ClInclude>
<ClInclude Include="include\templates\items.h">
<Filter>Header Files</Filter>
<Filter>Header Files\templates</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\console.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\init.cpp">
<ClCompile Include="src\startup.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\gamedata.cpp">
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ After that, for non-Windows platforms, I've added a CMake build configuration. W
* WSL (Ubuntu) using GCC and ncurses
* MacOS using (MacOS native) Clang and ncurses

Oh, yeah, the game is in Dutch, although the source code itself is now fully in English. I guess international awareness & orientation is something that developed in me over the past couple of decades...
The game was originally only available in the Dutch language, but has now been translated to English as a second language. The source code itself is now fully in English, also. I guess international awareness & orientation is something that developed in me over the past couple of decades, but here we are. (Note: getting R136 to start in English requires the `-e` command line argument to be passed to it; Dutch is still the default.)

## Credits

Expand Down
10 changes: 10 additions & 0 deletions cpp.hint
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Hint files help the Visual Studio IDE interpret Visual C++ identifiers
// such as names of functions and macros.
// For more information see https://go.microsoft.com/fwlink/?linkid=865984
#define in_the_forest
#define in_the_swamp
#define at_an_open_space
#define smelly_surface
#define in_an_empty_cave
#define in_a_stairwell_cave
#define other_levels
4 changes: 3 additions & 1 deletion include/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ AnimateStatus operator++(AnimateStatus& status, int);
AnimateStatus& operator++(AnimateStatus& status);

#include "templates/base.h"
#include "inlines/base.h"
#include "inlines/base.h"

#define select(...) select_language_param(core.language, __VA_ARGS__)
8 changes: 5 additions & 3 deletions include/commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

namespace commands
{
bool finish();
bool finish(CoreData& core);

void wait(void);
void wait(CoreData& core);

void show_status(CoreData& core);

void show_help(void);
void switch_language(CoreData& core);

void show_help(CoreData& core);

void use(CoreData& core, ItemID item_id);

Expand Down
6 changes: 3 additions & 3 deletions include/inlines/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ inline bool RoomConnections::is_open(Command direction) const
return (*this)[direction] != RoomID::undefined;
}

inline Item::Item(const string name, const wstring description, RoomID room, AnimateID usable_on, AnimateStatus sets_target_to_status) :
name(name),
description(description),
inline Item::Item(const std::vector <string> names, const std::vector <wstring> descriptions, RoomID room, AnimateID usable_on, AnimateStatus sets_target_to_status) :
names(names),
descriptions(descriptions),
room(room),
usable_on(usable_on),
sets_target_to_status(sets_target_to_status)
Expand Down
5 changes: 5 additions & 0 deletions include/inlines/console.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,3 +323,8 @@ inline InputWindow& Console::input()
{
return *input_window;
}

inline void Console::set_language(Language language)
{
setup_windows(language);
}
6 changes: 3 additions & 3 deletions include/inlines/items.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ inline bool ThermalSuit::use(CoreData& core)
return false;
}

inline CombinableItem::CombinableItem(string name, const wstring description, RoomID room, ItemID combines_with)
: Item(name, description, room, item::combines_with(combines_with)) {}
inline CombinableItem::CombinableItem(const std::vector<string> names, const std::vector<wstring> descriptions, RoomID room, ItemID combines_with)
: Item(names, descriptions, room, item::combines_with(combines_with)) {}

inline bool CombinableItem::combines_with(ItemID item)
{
return item::combines_with(usable_on) == item;
}

inline Flashlight::Flashlight(string name, const wstring description, RoomID room) : CombinableItem(name, description, room, ItemID::batteries)
inline Flashlight::Flashlight(const std::vector<string> names, const std::vector <wstring> descriptions, RoomID room) : CombinableItem(names, descriptions, room, ItemID::batteries)
{
is_on = false;
has_bunny_batteries = false;
Expand Down
7 changes: 4 additions & 3 deletions include/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ struct ParseData
};

class Parser {
static string dont_own_item_format_string;
static string commands[];
static const std::vector<string> dont_own_item_format_string;
static const std::vector<string> commands[];
static const std::vector<string> interjections[];

ParseData parse_data;

void parse_combine_parameters(CoreData& core, ParseData& parse_data, const string& param_string);
bool parse_owned_item_command_param(CoreData& core, ParseData& parse_data, const string& command, const string& parse_string);
bool check_found_item(ParseData& parse_data, ItemID item, const string& item_name, const string undefined_item_format_string);
bool check_found_item(CoreData& core, ParseData& parse_data, ItemID item, const string& item_name, const string undefined_item_format_string);
ItemID find_owned_item(CoreData& core, const string& item_name);
ItemID find_laying_item(CoreData& core, string& item_name);

Expand Down
5 changes: 3 additions & 2 deletions include/startup.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
namespace startup
{
void run_intro();
void show_splashscreen(void);
void show_start_message(void);
void show_splashscreen(CoreData& core);
void show_start_message(CoreData& core);
void initialize(CoreData& core);
void parse_arguments(CoreData& core, int argc, char* argv[]);
}
37 changes: 37 additions & 0 deletions include/templates/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//templates/base.h

#include "types/base.h"
#include <cstdarg>
#include <stdexcept>

template<class TEntity>
Expand Down Expand Up @@ -112,4 +113,40 @@ template<class TKey, class TValue>
void EntityMap<TKey, TValue>::clear()
{
map.clear();
}

template<class TParam>
constexpr TParam select_language_param(Language language, TParam first_param...)
{
auto param_index = to_value(language);
if (param_index == 0)
return first_param;

constexpr auto language_count = to_value(Language::COUNT);
std::va_list params;
TParam selected_param = TParam();

va_start(params, first_param);
for (int i = 1; i <= param_index && i < language_count; i++)
selected_param = va_arg(params, TParam);

va_end(params);

return selected_param;
}

template<class TChar>
const std::basic_string<TChar> empty_string = std::basic_string<TChar>();

template<class TChar>
const std::basic_string<TChar> &select_language_param(Language language, const std::vector<std::basic_string<TChar>>& texts)
{
auto language_value = to_value(language);
return (int)texts.size() > language_value ? texts[language_value] : empty_string<TChar>;
}

template<class TArrayType>
const TArrayType& select_language_param(Language language, const TArrayType* values)
{
return values[to_value(language)];
}
56 changes: 34 additions & 22 deletions include/types/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <memory>
#include <string>

#define get_y_or_n() (tolower(console.main().get_char_input(select("jJnN", "yYnN"))) == select((int)'j', (int)'y'))

using std::string;
using std::wstring;

Expand Down Expand Up @@ -86,6 +88,7 @@ enum class Command : char
finish,
status,
help,
language,

COUNT, undefined = -1
};
Expand Down Expand Up @@ -183,6 +186,14 @@ enum class AnimateStatus : char
undefined = -1
};

enum class Language : int
{
Dutch = 0,
English,

COUNT, undefined = -1
};

class RoomConnections
{
std::map<Command, RoomID> connections;
Expand All @@ -207,38 +218,38 @@ struct Entity

struct Room : Entity<RoomID>
{
const wstring name;
const wstring description;
const std::vector<wstring> names;
const std::vector<wstring> descriptions;
RoomType type;
RoomConnections connections;

protected:
Room(const wstring name, const wstring description, RoomType type) : name(name), description(description), type(type) {}
Room(const wstring name, RoomType type) : name(name), description(L""), type(type) {}
Room(const std::vector<wstring> names, const std::vector<wstring> descriptions, RoomType type) : names(names), descriptions(descriptions), type(type) {}
Room(const std::vector<wstring> names, RoomType type) : names(names), descriptions(), type(type) {}
};

struct Forest : public Room
{
Forest(const wstring name, const wstring description) : Room(name, description, RoomType::forest) {}
Forest(const wstring name) : Room(name, RoomType::forest) {}
Forest(const std::vector<wstring> names, const std::vector<wstring> descriptions) : Room(names, descriptions, RoomType::forest) {}
Forest(const std::vector<wstring> names) : Room(names, RoomType::forest) {}
};

struct Outdoor : public Room
{
Outdoor(const wstring name, const wstring description) : Room(name, description, RoomType::outdoor) {}
Outdoor(const wstring name) : Room(name, RoomType::outdoor) {}
Outdoor(const std::vector<wstring> names, const std::vector<wstring> descriptions) : Room(names, descriptions, RoomType::outdoor) {}
Outdoor(const std::vector<wstring> names) : Room(names, RoomType::outdoor) {}
};

struct Indoor : public Room
{
Indoor(const wstring name, const wstring description) : Room(name, description, RoomType::indoor) {}
Indoor(const wstring name) : Room(name, RoomType::indoor) {}
Indoor(const std::vector<wstring> names, const std::vector<wstring> descriptions) : Room(names, descriptions, RoomType::indoor) {}
Indoor(const std::vector<wstring> names) : Room(names, RoomType::indoor) {}
};

struct Cave : public Room
{
Cave(const wstring name, const wstring description) : Room(name, description, RoomType::cave) {}
Cave(const wstring name) : Room(name, RoomType::cave) {}
Cave(const std::vector<wstring> names, const std::vector<wstring> descriptions) : Room(names, descriptions, RoomType::cave) {}
Cave(const std::vector<wstring> names) : Room(names, RoomType::cave) {}
};

struct CoreData;
Expand All @@ -259,20 +270,20 @@ struct Animate : Entity<AnimateID>

struct Item : Entity<ItemID>
{
const string name;
const wstring description;
const std::vector<string> names;
const std::vector<wstring> descriptions;
RoomID room;
AnimateID usable_on;

Item(const string name, const wstring description, RoomID room, AnimateID usable_on, AnimateStatus sets_target_to_status = AnimateStatus::undefined);
Item(const string name, const wstring description, RoomID room)
: Item(name, description, room, AnimateID::undefined) {}
Item(const std::vector <string> names, const std::vector <wstring> descriptions, RoomID room, AnimateID usable_on, AnimateStatus sets_target_to_status = AnimateStatus::undefined);
Item(const std::vector <string> names, const std::vector <wstring> descriptions, RoomID room)
: Item(names, descriptions, room, AnimateID::undefined) {}

Item(const string name, const wstring description, AnimateID usable_on, AnimateStatus sets_target_to_status = AnimateStatus::undefined)
: Item(name, description, RoomID::undefined, usable_on, sets_target_to_status) {}
Item(const std::vector <string> names, const std::vector <wstring> descriptions, AnimateID usable_on, AnimateStatus sets_target_to_status = AnimateStatus::undefined)
: Item(names, descriptions, RoomID::undefined, usable_on, sets_target_to_status) {}

Item(const string name, const wstring description)
: Item(name, description, RoomID::undefined, AnimateID::undefined) {}
Item(const std::vector <string> names, const std::vector <wstring> descriptions)
: Item(names, descriptions, RoomID::undefined, AnimateID::undefined) {}

void inspect(CoreData& core);
virtual bool use(CoreData& core);
Expand Down Expand Up @@ -349,11 +360,12 @@ struct CoreData
Flashlight& flashlight();
std::vector<RoomID> paperroute;
Status status{};
Language language;

CoreData();

void set_flashlight(Flashlight* flashlight_ptr);

private:
Flashlight* flashlight_ptr;
};
};
7 changes: 4 additions & 3 deletions include/types/console.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class Window
bool end_line();
bool empty_line();

void wait_for_key(bool prompt = false);
void wait_for_key(bool prompt = false, Language language = static_cast<Language>(0));
int get_char_input(const string& allowed);
};

Expand Down Expand Up @@ -165,7 +165,7 @@ class Console

Window& banner();

void setup_windows();
void setup_windows(Language language = Language::undefined);

public:
Console();
Expand All @@ -176,7 +176,8 @@ class Console
InputWindow& input();

void process_resize();
void initialize();
void initialize(Language language);
void set_language(Language language);
void release();
CursorType get_cursor();
void set_cursor(CursorType type);
Expand Down
3 changes: 2 additions & 1 deletion include/types/general.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace general
{
void force_exit(void);
void force_exit(Language language);
void show_arguments();
void sleep_ms(int count);
}
Loading

0 comments on commit 1cf5fc5

Please sign in to comment.