-
Notifications
You must be signed in to change notification settings - Fork 12
/
midgardmapblock.h
120 lines (97 loc) · 4.17 KB
/
midgardmapblock.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
* This file is part of the modding toolset for Disciples 2.
* (https://github.com/VladimirMakeev/D2ModdingToolset)
* Copyright (C) 2021 Vladimir Makeev.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MIDGARDMAPBLOCK_H
#define MIDGARDMAPBLOCK_H
#include "categoryids.h"
#include "midgardid.h"
#include "midscenarioobject.h"
#include "mqpoint.h"
#include "terraincountmap.h"
#include <cstdint>
namespace game {
struct IMidgardObjectMap;
struct IMidgardStreamEnv;
struct LGroundCategory;
struct LTerrainCategory;
/*
Tile contents:
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
| forest index 2 | forest index | | tile variation | ground |terrain |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
*/
/** Represents block of tiles in scenario file and game. */
struct CMidgardMapBlock : public IMidScenarioObject
{
std::uint32_t tiles[32]; /**< 8 tiles along the X axis by 4 tiles along the Y axis. */
CMqPoint position;
};
assert_size(CMidgardMapBlock, 144);
static constexpr inline TerrainId tileTerrain(std::uint32_t tile)
{
return static_cast<TerrainId>(tile & 7);
}
static constexpr inline GroundId tileGround(std::uint32_t tile)
{
return static_cast<GroundId>((tile >> 3) & 7);
}
static constexpr inline std::uint8_t tileForestIndex2(std::uint32_t tile)
{
return tile >> 26;
}
namespace CMidgardMapBlockApi {
struct Api
{
/** Allocates memory for map block object and calls constructor. */
using Allocate = CMidgardMapBlock*(__stdcall*)(const CMidgardID* blockId);
Allocate allocate;
using Constructor = CMidgardMapBlock*(__thiscall*)(CMidgardMapBlock* thisptr,
const CMidgardID* blockId);
Constructor constructor;
/** Counts number of tiles with plain ground and their terrain coverage for each race. */
using CountTerrainCoverage = bool(__thiscall*)(const CMidgardMapBlock* thisptr,
TerrainCountMap* terrainCoverage,
int* plainTiles);
CountTerrainCoverage countTerrainCoverage;
/** Sets terrain for tile at specified map position. */
using SetTerrain = bool(__thiscall*)(CMidgardMapBlock* thisptr,
const LTerrainCategory* terrain,
const CMqPoint* position);
SetTerrain setTerrain;
/** Returns terrain for tile at specified position. */
using GetTerrain = bool(__thiscall*)(const CMidgardMapBlock* thisptr,
LTerrainCategory* terrain,
const CMqPoint* position);
GetTerrain getTerrain;
/** Sets ground for tile at specified map position. */
using SetGround = bool(__thiscall*)(CMidgardMapBlock* thisptr,
const LGroundCategory* ground,
const CMqPoint* position);
SetGround setGround;
/** Returns ground for tile at specified position. */
using GetGround = bool(__thiscall*)(CMidgardMapBlock* thisptr,
LGroundCategory* ground,
const CMqPoint* position);
GetGround getGround;
};
Api& get();
IMidScenarioObjectVftable* vftable();
} // namespace CMidgardMapBlockApi
} // namespace game
#endif // MIDGARDMAPBLOCK_H