forked from steaphangreene/acidmud
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmind_craft.cpp
More file actions
435 lines (422 loc) · 13.1 KB
/
mind_craft.cpp
File metadata and controls
435 lines (422 loc) · 13.1 KB
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
// *************************************************************************
// This file is part of AcidMUD by Steaphan Greene
//
// Copyright 1999-2022 Steaphan Greene <steaphan@gmail.com>
//
// AcidMUD 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.
//
// AcidMUD 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 AcidMUD (see the file named "COPYING");
// If not, see <http://www.gnu.org/licenses/>.
//
// *************************************************************************
#include <string>
#include <vector>
#include "color.hpp"
#include "log.hpp"
#include "mind.hpp"
#include "object.hpp"
#include "properties.hpp"
#include "tags.hpp"
#include "utils.hpp"
struct Project {
std::vector<uint32_t> tags_;
std::u8string short_;
std::u8string desc_;
std::u8string long_template_;
skill_pair prop_ = {prhash(u8"None"), 0};
uint32_t material_;
uint32_t amount_ = 1000;
uint32_t time_ = 1;
uint32_t max_qty_ = 1;
ItemAttrs attrs_ = {1000, 100, 100, 10};
};
static std::vector<Project> projects = {
{{crc32c(u8"collier"), crc32c(u8"kiln")},
u8"a piece of charcoal",
u8"a piece of high-quality charcoal",
u8"Created in {} by {}, Master Collier.",
{prhash(u8"Pure Charcoal"), 100},
prhash(u8"Raw Wood"),
200,
100,
1000,
{1000, 100, 100, 10}},
{{crc32c(u8"collier"), crc32c(u8"kiln")},
u8"a piece of charcoal",
u8"a piece of high-quality charcoal",
u8"Created in {} by {}, Master Collier.",
{prhash(u8"Pure Charcoal"), 100},
prhash(u8"Pure Wood"),
100,
100,
1000,
{1000, 100, 100, 10}},
{{crc32c(u8"sawyer"), crc32c(u8"sawmill")},
u8"a wooden beam",
u8"a large piece of finished lumber",
u8"Created in {} by {}, Master Sawyer.",
{prhash(u8"Pure Wood"), 100000},
prhash(u8"Raw Wood"),
200000,
100,
1,
{1000, 100, 100, 10}},
{{crc32c(u8"sawyer"), crc32c(u8"sawmill")},
u8"a wooden post",
u8"a large piece of finished lumber",
u8"Created in {} by {}, Master Sawyer.",
{prhash(u8"Pure Wood"), 9000},
prhash(u8"Pure Wood"),
10000,
100,
10,
{1000, 100, 100, 10}},
{{crc32c(u8"sawyer"), crc32c(u8"sawmill")},
u8"a wooden board",
u8"a piece of finished lumber",
u8"Created in {} by {}, Master Sawyer.",
{prhash(u8"Pure Wood"), 2000},
prhash(u8"Pure Wood"),
3000,
100,
10,
{1000, 100, 100, 10}},
{{crc32c(u8"sawyer"), crc32c(u8"sawmill")},
u8"a wooden stake",
u8"a piece of finished lumber",
u8"Created in {} by {}, Master Sawyer.",
{prhash(u8"Pure Wood"), 200},
prhash(u8"Pure Wood"),
250,
100,
10,
{1000, 100, 100, 10}},
{{crc32c(u8"woodworker")},
u8"an axe handle",
u8"a high-quality wooden axe handle",
u8"Created in {} by {}, Master Woodworker.",
{prhash(u8"Made of Wood"), 100},
prhash(u8"Pure Wood"),
200,
10,
1,
{1000, 100, 100, 220}},
{{crc32c(u8"smelter"), crc32c(u8"crucible")},
u8"a platinum bar",
u8"a bar of pure platinum",
u8"Smelted in {} by {}, Master Smetler.",
{prhash(u8"Pure Platinum"), 100},
prhash(u8"Raw Platinum"),
100,
50,
10,
{1000, 100, 100, 30000}},
{{crc32c(u8"smelter"), crc32c(u8"crucible")},
u8"a gold bar",
u8"a bar of pure gold",
u8"Smelted in {} by {}, Master Smetler.",
{prhash(u8"Pure Gold"), 100},
prhash(u8"Raw Gold"),
100,
50,
10,
{1000, 100, 100, 3000}},
{{crc32c(u8"smelter"), crc32c(u8"crucible")},
u8"a silver bar",
u8"a bar of pure silver",
u8"Smelted in {} by {}, Master Smetler.",
{prhash(u8"Pure Silver"), 100},
prhash(u8"Raw Silver"),
100,
50,
10,
{1000, 100, 100, 300}},
{{crc32c(u8"smelter"), crc32c(u8"crucible")},
u8"a copper bar",
u8"a bar of pure copper",
u8"Smelted in {} by {}, Master Smetler.",
{prhash(u8"Pure Copper"), 100},
prhash(u8"Raw Copper"),
100,
50,
10,
{1000, 100, 100, 30}},
{{crc32c(u8"smelter"), crc32c(u8"crucible")},
u8"a tin bar",
u8"a bar of pure tin",
u8"Smelted in {} by {}, Master Smetler.",
{prhash(u8"Pure Tin"), 100},
prhash(u8"Raw Tin"),
100,
50,
10,
{1000, 100, 100, 10}},
{{crc32c(u8"smelter"), crc32c(u8"crucible")},
u8"a iron bar",
u8"a bar of pure iron",
u8"Smelted in {} by {}, Master Smetler.",
{prhash(u8"Pure Iron"), 100},
prhash(u8"Raw Iron"),
100,
100,
10,
{1000, 100, 100, 20}},
{{crc32c(u8"metalsmith"), crc32c(u8"crucible")},
u8"a platinum coin blank",
u8"a blank disk of pure platinum",
u8"Formed in {} by {}, Master Metalsmith.",
{prhash(u8"Made of Platinum"), 30},
prhash(u8"Pure Platinum"),
30,
100,
33,
{30, 1, 1, 9000}},
{{crc32c(u8"metalsmith"), crc32c(u8"crucible")},
u8"a gold coin blank",
u8"a blank disk of pure gold",
u8"Formed in {} by {}, Master Metalsmith.",
{prhash(u8"Made of Gold"), 30},
prhash(u8"Pure Gold"),
30,
100,
33,
{30, 1, 1, 900}},
{{crc32c(u8"metalsmith"), crc32c(u8"crucible")},
u8"a silver coin blank",
u8"a blank disk of pure silver",
u8"Formed in {} by {}, Master Metalsmith.",
{prhash(u8"Made of Silver"), 30},
prhash(u8"Pure Silver"),
30,
100,
33,
{30, 1, 1, 90}},
{{crc32c(u8"metalsmith"), crc32c(u8"crucible")},
u8"a copper coin blank",
u8"a blank disk of pure copper",
u8"Formed in {} by {}, Master Metalsmith.",
{prhash(u8"Made of Copper"), 30},
prhash(u8"Pure Copper"),
30,
100,
33,
{30, 1, 1, 9}},
{{crc32c(u8"metalsmith"), crc32c(u8"crucible")},
u8"a steel bar",
u8"a bar of pure steel",
u8"Alloyed in {} by {}, Master Metalsmith.",
{prhash(u8"Pure Steel"), 100},
prhash(u8"Pure Iron"),
100,
1000,
1,
{1000, 100, 100, 100}},
{{crc32c(u8"coinmaker"), crc32c(u8"coinpress")},
u8"a platinum piece",
u8"A standard one-ounce platinum piece.",
u8"Stamped in {} by {}, Master Coinmaker.",
{prhash(u8"Money"), 10000},
prhash(u8"Made of Platinum"),
30,
10,
1,
{30, 1, 1, 10000}},
{{crc32c(u8"coinmaker"), crc32c(u8"coinpress")},
u8"a gold piece",
u8"A standard one-ounce gold piece.",
u8"Stamped in {} by {}, Master Coinmaker.",
{prhash(u8"Money"), 1000},
prhash(u8"Made of Gold"),
30,
10,
1,
{30, 1, 1, 1000}},
{{crc32c(u8"coinmaker"), crc32c(u8"coinpress")},
u8"a silver piece",
u8"A standard one-ounce silver piece.",
u8"Stamped in {} by {}, Master Coinmaker.",
{prhash(u8"Money"), 100},
prhash(u8"Made of Silver"),
30,
10,
1,
{30, 1, 1, 100}},
{{crc32c(u8"coinmaker"), crc32c(u8"coinpress")},
u8"a copper piece",
u8"A standard one-ounce copper piece.",
u8"Stamped in {} by {}, Master Coinmaker.",
{prhash(u8"Money"), 10},
prhash(u8"Made of Copper"),
30,
10,
1,
{30, 1, 1, 10}},
};
struct Plan {
const Project* project;
Object* material;
Object* equipment = nullptr;
};
void Mind::StartNewProject() {
std::vector<Plan> materials;
auto wares = body->Room()->PickObjects(u8"everything", LOC_INTERNAL);
for (auto item : wares) {
if (item->ActTarg(act_t::SPECIAL_OWNER) == body->Room()) {
for (const auto& proj : projects) {
bool relevant = true;
Object* equip = nullptr;
for (auto tag : proj.tags_) {
if (!body->HasTag(tag)) {
relevant = false;
for (auto tool : body->PickObjects(u8"everything", LOC_NEARBY)) {
if (tool->HasTag(tag)) {
equip = tool;
relevant = true;
}
}
if (!relevant) {
break;
}
}
}
if (relevant && item->Skill(proj.material_) >= static_cast<int>(proj.amount_)) {
materials.emplace_back(Plan{&proj, item, equip});
break;
}
}
/*
if (body->HasTag(crc32c(u8"smelter"))) {
if (item->Skill(prhash(u8"Pure Charcoal")) || item->Skill(prhash(u8"Raw Copper")) ||
item->Skill(prhash(u8"Raw Silver")) || item->Skill(prhash(u8"Raw Gold")) ||
item->Skill(prhash(u8"Raw Platinum")) || item->Skill(prhash(u8"Raw Tin"))) {
materials.push_back(item);
}
} else if (body->HasTag(crc32c(u8"metalsmith"))) {
if (item->Skill(prhash(u8"Pure Charcoal")) || item->Skill(prhash(u8"Pure Iron")) ||
item->Skill(prhash(u8"Pure Copper")) || item->Skill(prhash(u8"Pure Tin"))) {
materials.push_back(item);
}
} else if (body->HasTag(crc32c(u8"coinmaker"))) {
if (item->Skill(prhash(u8"Pure Charcoal")) || item->Skill(prhash(u8"Pure Copper")) ||
item->Skill(prhash(u8"Pure Silver")) || item->Skill(prhash(u8"Pure Gold")) ||
item->Skill(prhash(u8"Pure Platinum"))) {
materials.push_back(item);
}
}
*/
}
}
/*
std::ranges::sort(materials, [](const Object* a, const Object* b) {
size_t rat_a = a->Skill(prhash(u8"Raw Wood"));
rat_a += a->Skill(prhash(u8"Pure Wood"));
size_t rat_b = b->Skill(prhash(u8"Raw Wood"));
rat_b += b->Skill(prhash(u8"Raw Wood"));
rat_a *= 1000UL;
rat_b *= 1000UL;
rat_a /= a->Value();
rat_b /= b->Value();
return rat_a > rat_b;
});
*/
if (materials.size() > 0) {
const Project* proj = materials.front().project;
Object* mat = materials.front().material;
Object* equip = materials.front().equipment;
if (mat->Quantity() > 1) {
mat = mat->Split(1);
}
body->Parent()->SendOut(ALL, 0, u8";s grabs ;s and begins working on it.\n", u8"", body, mat);
mat->SetSkill(prhash(u8"Incomplete"), proj->time_);
mat->SetShortDesc(u8"a piece of work");
mat->AddAct(act_t::SPECIAL_OWNER, body);
mat->SetPosition(pos_t::LIE); // No longer up for sale.
body->AddAct(act_t::WORK, mat);
Object* goal = new Object(mat);
goal->SetDescs(
proj->short_,
u8"",
proj->desc_,
fmt::format(proj->long_template_, goal->Zone()->ShortDesc(), body->Name()));
if (proj->prop_.first != prhash(u8"None")) {
goal->SetSkill(proj->prop_.first, proj->prop_.second);
}
goal->SetWeight(proj->attrs_.weight);
goal->SetSize(proj->attrs_.size);
goal->SetVolume(proj->attrs_.volume);
goal->SetValue(proj->attrs_.value);
if (proj->max_qty_ > 1 && proj->amount_ > 0 &&
mat->Skill(proj->material_) >= static_cast<int>(proj->amount_) * 2) {
goal->SetQuantity(std::min(
proj->max_qty_, static_cast<uint32_t>(mat->Skill(proj->material_)) / proj->amount_));
}
goal->SetPosition(pos_t::LIE);
if (equip) {
mat->Travel(equip);
body->Parent()->SendOut(ALL, 0, u8";s throws it into ;s.\n", u8"", body, equip);
}
}
}
void Mind::ContinueWorkOn(Object* project) {
auto todo = project->Skill(prhash(u8"Incomplete")) - body->ModAttribute(5);
if (todo > 0) {
project->SetSkill(prhash(u8"Incomplete"), todo);
} else {
project->ClearSkill(prhash(u8"Incomplete"));
if (project->Contents().size() > 0) {
Object* old_proj = project;
project = project->Contents().front();
project->Travel(project->Room());
delete old_proj;
}
if (project->Parent() != body->Room()) {
project->Travel(body->Room());
}
body->AddAct(act_t::WORK);
project->AddAct(act_t::SPECIAL_OWNER, body->Room());
project->SetPosition(pos_t::PROP); // Put it up for sale.
project->TryCombine();
body->Parent()->SendOut(
ALL,
0,
u8";s completes {} and places it with the rest of the wares.\n",
u8"",
body,
nullptr,
project->ShortDesc());
}
}
// Returns how much NPC/MOB would pay for item, or 0.
size_t Mind::NPCWouldBuyFor(const Object* item) {
for (const auto& proj : projects) {
bool relevant = true;
// Object* equip = nullptr;
for (auto tag : proj.tags_) {
if (!body->HasTag(tag)) {
relevant = false;
for (auto tool : body->PickObjects(u8"everything", LOC_NEARBY)) {
if (tool->HasTag(tag)) {
// equip = tool; // TODO: Confirm Tool Availability
relevant = true;
}
}
if (!relevant) {
break;
}
}
}
if (relevant && item->Skill(proj.material_) >= static_cast<int>(proj.amount_)) {
return item->Value() * item->Quantity();
}
}
return 0;
}