-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathSpriteMaps.cpp
132 lines (123 loc) · 4.23 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
#include "common.h"
#include "SpriteMaps.h"
#include "GroundMaterialConfiguration.h"
#include "ContentLoader.h"
#include "GUI.h"
#include "TileTree.h"
#include "TileTypes.h"
#include "StonesenseState.h"
c_sprite * GetTerrainSpriteMap(int in, DFHack::t_matglossPair material, std::vector<std::unique_ptr<TerrainConfiguration>>& configTable, uint16_t form)
{
// in case we need to return nothing
static c_sprite defaultSprite{};
defaultSprite.reset();
defaultSprite.set_sheetindex(UNCONFIGURED_INDEX);
defaultSprite.set_fileindex(INVALID_INDEX);
defaultSprite.set_needoutline(1);
int tempform;
switch (form)
{
using df::item_type;
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;
}
// find mat config
auto& terrainMat = terrain->getTerrainMaterials(material.type);
if (!terrainMat) {
if(terrain->getDefaultSprite(tempform).get_sheetindex() == UNCONFIGURED_INDEX) {
return &(terrain->getDefaultSprite(0));
} else {
return &(terrain->getDefaultSprite(tempform));
}
}
if(material.index == -1) {
if (terrainMat->getSprite(tempform).get_sheetindex() == UNCONFIGURED_INDEX) {
return &(terrainMat->getSprite(0));
} else {
return &(terrainMat->getSprite(tempform));
}
}
// return subtype, type default or terrain default as available
// do map lookup
return &terrainMat->getOverridingMaterial(tempform, material, terrain);
}
c_sprite * GetFloorSpriteMap(int in, DFHack::t_matglossPair material, uint16_t form)
{
return GetTerrainSpriteMap(in, material, stonesenseState.contentLoader->terrainFloorConfigs, form);
}
c_sprite * GetTileSpriteMap(int in, DFHack::t_matglossPair material, uint16_t form)
{
return GetTerrainSpriteMap(in, material, stonesenseState.contentLoader->terrainWallConfigs, form);
}
c_tile_tree * GetTreeVegetation(df::tiletype_shape shape, df::tiletype_special special, int index)
{
int base_sprite = SPRITEOBJECT_BLUEPRINT;
std::vector<std::unique_ptr<VegetationConfiguration>>* graphicSet;
bool live=true;
bool grown=true;
auto& contentLoader = stonesenseState.contentLoader;
switch(shape) {
using df::tiletype_shape;
case tiletype_shape::TRUNK_BRANCH:
if (special == df::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 == df::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 == df::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 nullptr;
}
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;
}