-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathresource.cpp
195 lines (179 loc) · 4.32 KB
/
resource.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#include "resource.h"
#include "stringfunc.h"
#include "rng.h"
bool Resource_amount::is_infinite()
{
return (amount == INFINITE_RESOURCE);
}
bool Crop_amount::is_infinite()
{
return (amount == INFINITE_RESOURCE);
}
bool Mineral_amount::is_infinite()
{
return (amount == INFINITE_RESOURCE);
}
Mineral_amount Mineral_amount::make_small()
{
Mineral_amount ret;
ret.type = type;
ret.amount = rng( amount * .1, amount * .2);
return ret;
}
Mineral_amount Mineral_amount::randomize()
{
Mineral_amount ret;
ret.type = type;
ret.amount = rng( amount * .8, amount * 1.2);
return ret;
}
Resource lookup_resource(std::string name)
{
name = no_caps( trim( name ) );
for (int i = 0; i < RES_MAX; i++) {
Resource ret = Resource(i);
if (name == no_caps( Resource_data[ret]->name )) {
return ret;
}
}
return RES_NULL;
}
Luxury_type lookup_luxury_type(std::string name)
{
name = no_caps( trim( name ) );
for (int i = 0; i < LUX_MAX; i++) {
Luxury_type ret = Luxury_type(i);
if (no_caps( luxury_type_name(ret) ) == name) {
return ret;
}
}
return LUX_NULL;
}
std::string luxury_type_name(Luxury_type type)
{
switch (type) {
case LUX_NULL: return "NULL";
case LUX_SPICE: return "spice";
case LUX_SMOKABLE: return "smokable";
case LUX_HALLUCINOGEN: return "hallucinogen";
case LUX_COATS: return "warm coats";
case LUX_HOUSEWARES: return "housewares";
case LUX_MAX: return "BUG - LUX_MAX";
default: return "BUG - Unnamed Luxury_type";
}
return "BUG - Escaped luxury_type_name() switch!";
}
Crop_type lookup_crop_type(std::string name)
{
name = no_caps( trim( name ) );
for (int i = 0; i < CROPTYPE_MAX; i++) {
Crop_type ret = Crop_type(i);
if (no_caps(crop_type_name(ret)) == name) {
return ret;
}
}
return CROPTYPE_NULL;
}
std::string crop_type_name(Crop_type type)
{
switch (type) {
case CROPTYPE_NULL: return "NULL";
case CROPTYPE_FOOD: return "food";
case CROPTYPE_SPICE: return "spice";
case CROPTYPE_DRUG: return "drug";
case CROPTYPE_POISON: return "poison";
case CROPTYPE_FIBER: return "fiber";
case CROPTYPE_OTHER: return "other";
case CROPTYPE_MAX: return "BUG - CROPTYPE_MAX";
default: return "Unnamed Crop_type";
}
return "BUG - Escaped crop_type_name() switch";
}
nc_color crop_type_color(Crop_type type)
{
switch (type) {
case CROPTYPE_NULL: return c_ltgray;
case CROPTYPE_FOOD: return c_ltgreen;
case CROPTYPE_SPICE: return c_yellow;
case CROPTYPE_DRUG: return c_magenta;
case CROPTYPE_POISON: return c_ltred;
case CROPTYPE_FIBER: return c_ltblue;
case CROPTYPE_OTHER: return c_brown;
case CROPTYPE_MAX: return c_ltgray;
default: return c_ltgray;
}
return c_ltgray;
}
Crop search_for_crop(std::string name)
{
name = no_caps( trim(name) );
for (int i = 1; i < CROP_MAX; i++) {
Crop ret = Crop(i);
if (Crop_data[ret]->name.find(name) != std::string::npos) {
return ret;
}
}
return CROP_NULL;
}
Mineral search_for_mineral(std::string name)
{
name = no_caps( trim(name) );
for (int i = 1; i < MINERAL_MAX; i++) {
Mineral ret = Mineral(i);
if (Mineral_data[ret]->name.find(name) != std::string::npos) {
return ret;
}
}
return MINERAL_NULL;
}
std::string mineral_amount_ranking(Mineral_amount min_amt)
{
if (min_amt.amount == INFINITE_RESOURCE) {
return "unlimited";
}
if (min_amt.type == MINERAL_NULL || min_amt.type == MINERAL_MAX) {
return "";
}
if (min_amt.amount <= 100) {
return "trace";
}
if (min_amt.amount <= 500) {
return "a little";
}
if (min_amt.amount <= 2000) {
return "some";
}
if (min_amt.amount <= 5000) {
return "lots of";
}
if (min_amt.amount <= 8000) {
return "tons of";
}
return "a huge amount of";
}
// "<return> trees"
std::string trees_amount_ranking(int wood)
{
if (wood == 0) {
return "no";
}
if (wood < 40) {
return "one or two";
}
if (wood < 100) {
return "very few";
}
if (wood < 300) {
return "few";
}
if (wood < 1000) {
return "many";
}
if (wood < 10000) {
return "dense";
}
if (wood < 30000) {
return "very dense";
}
return "overgrown with";
}