From 7a12356220753d9e62d177db8d75ad4275608567 Mon Sep 17 00:00:00 2001 From: Ted John Date: Sat, 27 Jan 2018 16:44:38 +0000 Subject: [PATCH] Implement the industry struct and manager (#58) --- src/openloco/industry.cpp | 9 +++++++++ src/openloco/industry.h | 27 +++++++++++++++++++++++++++ src/openloco/industrymgr.cpp | 24 ++++++++++++++++++++++++ src/openloco/industrymgr.h | 13 +++++++++++++ src/openloco/openloco.vcxproj | 4 ++++ 5 files changed, 77 insertions(+) create mode 100644 src/openloco/industry.cpp create mode 100644 src/openloco/industry.h create mode 100644 src/openloco/industrymgr.cpp create mode 100644 src/openloco/industrymgr.h diff --git a/src/openloco/industry.cpp b/src/openloco/industry.cpp new file mode 100644 index 00000000..dfa3753f --- /dev/null +++ b/src/openloco/industry.cpp @@ -0,0 +1,9 @@ +#include "industry.h" + +namespace openloco +{ + bool industry::empty() const + { + return name == string_ids::null; + } +} diff --git a/src/openloco/industry.h b/src/openloco/industry.h new file mode 100644 index 00000000..a52c52ee --- /dev/null +++ b/src/openloco/industry.h @@ -0,0 +1,27 @@ +#pragma once + +#include "localisation/stringmgr.h" +#include +#include + +namespace openloco +{ + using industry_id_t = uint16_t; + + namespace industry_id + { + constexpr industry_id_t null = std::numeric_limits::max(); + } + +#pragma pack(push, 1) + struct industry + { + string_id name; + uint8_t pad_02[0xD5 - 0x02]; + uint16_t var_D5; + uint8_t pad_D7[0x453 - 0xD7]; + + bool empty() const; + }; +#pragma pack(pop) +} diff --git a/src/openloco/industrymgr.cpp b/src/openloco/industrymgr.cpp new file mode 100644 index 00000000..78080e56 --- /dev/null +++ b/src/openloco/industrymgr.cpp @@ -0,0 +1,24 @@ +#include "industrymgr.h" +#include "interop/interop.hpp" + +using namespace openloco::interop; + +namespace openloco::industrymgr +{ + static loco_global_array _industries; + + std::array& industries() + { + auto arr = (std::array*)_industries.get(); + return *arr; + } + + industry* get(industry_id_t id) + { + if (id >= _industries.size()) + { + return nullptr; + } + return &_industries[id]; + } +} diff --git a/src/openloco/industrymgr.h b/src/openloco/industrymgr.h new file mode 100644 index 00000000..83627e73 --- /dev/null +++ b/src/openloco/industrymgr.h @@ -0,0 +1,13 @@ +#pragma once + +#include "industry.h" +#include +#include + +namespace openloco::industrymgr +{ + constexpr size_t max_industries = 128; + + std::array& industries(); + industry* get(industry_id_t id); +} diff --git a/src/openloco/openloco.vcxproj b/src/openloco/openloco.vcxproj index a0ece30e..dcecc69c 100644 --- a/src/openloco/openloco.vcxproj +++ b/src/openloco/openloco.vcxproj @@ -21,6 +21,8 @@ + + @@ -63,6 +65,8 @@ + +