-
Notifications
You must be signed in to change notification settings - Fork 55
/
SpriteMaps.cpp
152 lines (144 loc) · 5.17 KB
/
SpriteMaps.cpp
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include "common.h"
#include "SpriteMaps.h"
#include "GroundMaterialConfiguration.h"
#include "ContentLoader.h"
#include "GUI.h"
#include "TileTree.h"
#include "TileTypes.h"
using namespace std;
using namespace DFHack;
using namespace df::enums;
c_sprite * GetTerrainSpriteMap(int in, t_matglossPair material, vector<std::unique_ptr<TerrainConfiguration>>& configTable, uint16_t form)
{
// in case we need to return nothing
static c_sprite* defaultSprite = new c_sprite;
defaultSprite->reset();
defaultSprite->set_sheetindex(UNCONFIGURED_INDEX);
defaultSprite->set_fileindex(INVALID_INDEX);
defaultSprite->set_needoutline(1);
int tempform;
switch (form)
{
case item_type::BAR:
tempform = FORM_BAR;
break;
case item_type::BLOCKS:
tempform = FORM_BLOCK;
break;
case item_type::BOULDER:
tempform = FORM_BOULDER;
break;
case item_type::WOOD:
tempform = FORM_LOG;
break;
default:
return defaultSprite;
}
// first check the input is sane
if( in < 0 || in >= (int)configTable.size() ) {
return defaultSprite;
}
// find a matching terrainConfig
TerrainConfiguration* terrain = configTable[in].get();
if (terrain == nullptr) {
return defaultSprite;
}
// check material sanity
if (material.type<0 || material.type >= (int16_t)terrain->terrainMaterials.size()) {
if(terrain->defaultSprite[tempform].first.get_sheetindex() == UNCONFIGURED_INDEX) {
return &(terrain->defaultSprite[0].first);
} else {
return &(terrain->defaultSprite[tempform].first);
}
}
// find mat config
TerrainMaterialConfiguration* terrainMat = terrain->terrainMaterials[material.type].get();
if (terrainMat == nullptr) {
if (terrain->defaultSprite[tempform].first.get_sheetindex() == UNCONFIGURED_INDEX) {
return &(terrain->defaultSprite[0].first);
} else {
return &(terrain->defaultSprite[tempform].first);
}
}
if(material.index == -1) {
if (terrainMat->defaultSprite[tempform].first.get_sheetindex() == UNCONFIGURED_INDEX) {
return &(terrainMat->defaultSprite[0].first);
} else {
return &(terrainMat->defaultSprite[tempform].first);
}
}
// return subtype, type default or terrain default as available
// do map lookup
map<int,pair<c_sprite, int>>::iterator it = terrainMat->overridingMaterials[tempform].find(material.index);
if (it != terrainMat->overridingMaterials[tempform].end()) {
return &(it->second.first);
}
if (terrainMat->defaultSprite[tempform].first.get_sheetindex() != UNCONFIGURED_INDEX) {
return &(terrainMat->defaultSprite[tempform].first);
}
it = terrainMat->overridingMaterials[0].find(material.index);
if (it != terrainMat->overridingMaterials[0].end()) {
return &(it->second.first);
}
if (terrainMat->defaultSprite[0].first.get_sheetindex() != UNCONFIGURED_INDEX) {
return &(terrainMat->defaultSprite[0].first);
}
return &(terrain->defaultSprite[0].first);
}
c_sprite * GetFloorSpriteMap(int in, t_matglossPair material, uint16_t form)
{
return GetTerrainSpriteMap(in, material, contentLoader->terrainFloorConfigs, form);
}
c_sprite * GetTileSpriteMap(int in, t_matglossPair material, uint16_t form)
{
return GetTerrainSpriteMap(in, material, contentLoader->terrainWallConfigs, form);
}
c_tile_tree * GetTreeVegetation(df::tiletype_shape shape, df::tiletype_special special, int index)
{
int base_sprite = SPRITEOBJECT_BLUEPRINT;
vector<std::unique_ptr<VegetationConfiguration>>* graphicSet;
bool live=true;
bool grown=true;
switch(shape) {
case tiletype_shape::TRUNK_BRANCH:
if (special == tiletype_special::DEAD) {
base_sprite = SPRITEOBJECT_TREE_DEAD;
graphicSet = &(contentLoader->treeConfigs);
live = false;
} else {
base_sprite = SPRITEOBJECT_TREE_OK;
graphicSet = &(contentLoader->treeConfigs);
}
break;
case tiletype_shape::SAPLING:
if (special == tiletype_special::DEAD) {
base_sprite = SPRITEOBJECT_SAPLING_DEAD;
live = false;
grown = false;
graphicSet = &(contentLoader->treeConfigs);
} else {
base_sprite = SPRITEOBJECT_SAPLING_OK;
grown = false;
graphicSet = &(contentLoader->treeConfigs);
}
break;
case tiletype_shape::SHRUB:
if (special == tiletype_special::DEAD) {
base_sprite = SPRITEOBJECT_SHRUB_DEAD;
live = false;
graphicSet = &(contentLoader->shrubConfigs);
} else {
base_sprite = SPRITEOBJECT_SHRUB_OK;
graphicSet = &(contentLoader->shrubConfigs);
}
break;
default:
return null;
}
c_tile_tree * configuredTree = getVegetationTree(*graphicSet,index,live,grown);
if (configuredTree->get_sheetindex() == -1) {
configuredTree->set_fileindex(-1); // should be set already, but...
configuredTree->set_sheetindex(base_sprite);
}
return configuredTree;
}