forked from Whales/Cataclysm2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathitem_type.cpp
967 lines (830 loc) · 24.3 KB
/
item_type.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
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
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
#include "item_type.h"
#include "stringfunc.h"
#include "window.h"
#include <sstream>
Item_type::Item_type()
{
uid = -1;
name = "bug";
sym = glyph();
weight = 0;
volume = 0;
for (int i = 0; i < DAMAGE_MAX; i++) {
damage[i] = 0;
}
to_hit = 0;
attack_speed = 0;
thrown_variance = Dice(8, 20, 0);
thrown_dmg_percent = 50;
thrown_speed = 0;
for (int i = 0; i < ITEM_FLAG_MAX; i++) {
flags.push_back(false);
}
mission_experience = 0;
}
Item_type::~Item_type()
{
}
Item_type_clothing::Item_type_clothing()
{
carry_capacity = 0;
armor_bash = 0;
armor_cut = 0;
armor_pierce = 0;
protection = 0;
encumbrance = 0;
for (int i = 0; i < BODY_PART_MAX; i++) {
covers[i] = false;
}
}
std::string Item_type_clothing::get_property_description()
{
std::stringstream ret;
ret << "<c=white>Covers:<c=/> ";
bool printed_any = false;
for (int i = 0; i < BODY_PART_MAX; i++) {
if (covers[i]) {
if (printed_any) {
ret << ", ";
} else {
printed_any = true;
}
ret << body_part_name( Body_part(i) );
}
}
ret << std::endl;
ret << "<c=ltblue>Storage space: ";
if (carry_capacity == 0) {
ret << "<c=dkgray>";
} else if (carry_capacity >= 25) { // TODO: Change / don't hardcode this
ret << "<c=white>";
} else {
ret << "<c=ltgray>";
}
ret << carry_capacity << "<c=/>\n";
ret << "<c=magenta>Encumbrance: ";
if (encumbrance == 0) {
ret << "<c=white>";
} else if (encumbrance < 3) {
ret << "<c=ltgray>";
} else if (encumbrance < 5) {
ret << "<c=ltred>";
} else {
ret << "<c=red>";
}
ret << encumbrance << std::endl;
// Set up vectors for use in color_gradient() below
std::vector<int> breakpoints;
breakpoints.push_back(0);
breakpoints.push_back(10);
std::vector<nc_color> colors;
colors.push_back( c_dkgray );
colors.push_back( c_ltgray );
colors.push_back( c_white );
ret << "<c=brown>Armor (bash): " <<
color_gradient(armor_bash, breakpoints, colors) << armor_bash <<
"<c=/>\n";
ret << "<c=brown>Armor (cut): " <<
color_gradient(armor_cut, breakpoints, colors) << armor_cut <<
"<c=/>\n";
ret << "<c=brown>Armor (pierce): " <<
color_gradient(armor_pierce, breakpoints, colors) << armor_pierce <<
"<c=/>\n";
return ret.str();
}
Item_type_ammo::Item_type_ammo()
{
damage = 0;
// When we hit a target, their effective armor is (armor * 10) / armor_pierce
// Thus, armor_pierce of 10 means "don't affect their armor at all"
armor_pierce = 10;
range = 0;
count = 100;
pellets = 1;
}
std::string Item_type_ammo::get_name_singular()
{
std::stringstream ret;
ret << "box of " << get_name();
return ret.str();
}
std::string Item_type_ammo::get_name_plural()
{
std::stringstream ret;
ret << "boxes of " << get_name();
return ret.str();
}
std::string Item_type_ammo::get_property_description()
{
std::stringstream ret;
ret << "<c=white>Type:<c=/> " << ammo_type << std::endl;
ret << "<c=cyan>Accuracy:<c=/> " << accuracy.str() << std::endl;
if (pellets > 1) {
ret << "<c=ltred>Pellets:<c=/> " << pellets << std::endl;
}
ret << "<c=red>Damage:<c=white> " << damage << "\n<c=ltblue>Armor Piercing: ";
if (armor_pierce == 10) {
ret << "<c=dkgray>None";
} else {
if (armor_pierce < 10) {
ret << "<c=red>";
} else {
ret << "<c=white>";
}
ret << "x" << armor_pierce / 10 << "." << armor_pierce % 10;
}
ret << "<c=/>\n";
ret << "<c=ltgray>Range: " << range << "<c=/>\n";
return ret.str();
}
Item_type_launcher::Item_type_launcher()
{
damage = 0;
recoil = 0;
durability = 100;
capacity = 15;
reload_ap = 300;
fire_ap = 100;
}
std::string Item_type_launcher::get_property_description()
{
std::stringstream ret;
ret << "<c=white>Ammo:<c=/> " << ammo_type << std::endl;
ret << "<c=ltred>Damage bonus:<c=/> " << (damage >= 0 ? "+" : "") <<
damage << std::endl;
ret << "<c=cyan>Accuracy:<c=/> " << accuracy.str() << std::endl;
ret << "<c=magenta>Recoil:<c=/> " << (recoil >= 0 ? "+" : "") <<
recoil << std::endl;
ret << "<c=brown>Durability:<c=/> " << durability << std::endl;
ret << "<c=ltblue>Capacity:<c=/> " << capacity << " rounds" << std::endl;
ret << "<c=green>Reload time:<c=/> " << reload_ap / 100 << "." <<
(reload_ap % 100) / 10 << reload_ap % 10 << " turns" << std::endl;
ret << "<c=ltgreen>Fire time:<c=/> " << fire_ap / 100 << "." <<
(fire_ap % 100) / 10 << fire_ap % 10 << " turns" << std::endl;
ret << "<c=red>Fire modes:<c=/> ";
// TODO: If there's special mods, like "snipe," handle them specially
if (modes.empty()) {
ret << "Single shot";
}
for (int i = 0; i < modes.size(); i++) {
ret << "[" << modes[i] << "] ";
}
return ret.str();
}
Item_type_food::Item_type_food()
{
food = 0;
water = 0;
charges = 1;
verb = "eat";
effect_chance = 100;
}
std::string Item_type_food::get_property_description()
{
std::stringstream ret;
ret << "<c=green>Nutrition: <c=/>" << food << std::endl;
ret << "<c=ltblue>Water: <c=/>" << water << std::endl;
return ret.str();
}
Item_type_tool::Item_type_tool()
{
def_charges = 0;
max_charges = 0;
countdown_timer = 0;
}
// We won't try to handle the Tool_action here - that's better done by hand
std::string Item_type_tool::get_property_description()
{
std::stringstream ret;
ret << "<c=yellow>Fuel:<c=/> ";
if (fuel.empty()) {
ret << "<c=dkgray>N/A<c=/>" << std::endl;
} else {
ret << fuel << std::endl;
}
ret << "<c=white>Max charges:<c=/> " << max_charges << std::endl;
ret << "<c=green>Time to apply:<c=/> ";
if (applied_action.real) {
ret << applied_action.ap_cost / 100 << ".";
if (applied_action.ap_cost % 100 < 10) {
ret << "0";
}
ret << applied_action.ap_cost % 100 << " turns";
} else {
ret << "N/A";
}
return ret.str();
}
void Item_type::assign_uid(int id)
{
uid = id;
}
std::string Item_type::get_data_name()
{
return name;
}
std::string Item_type::get_name()
{
if (display_name.empty()) {
return name;
}
return display_name;
}
// This is overloaded for Item_type classes that need more (like Item_type_ammo)
std::string Item_type::get_name_singular()
{
return get_name();
}
std::string Item_type::get_name_plural()
{
if (has_flag(ITEM_FLAG_PLURAL)) {
return get_name_singular();
} else if (plural_name.empty()) {
return get_name_singular() + "s";
}
return plural_name;
}
bool Item_type::load_data(std::istream &data)
{
std::string ident, junk;
bool set_name = false, set_glyph = false;
while (ident != "done" && !data.eof()) {
if ( ! (data >> ident) ) {
debugmsg("Couldn't read Item_type data (%s)",
(set_name ? name.c_str() : "Name not set!"));
return false;
}
ident = no_caps(ident);
if (!ident.empty() && ident[0] == '#') {
// It's a comment
std::getline(data, junk);
} else if (ident == "name:") {
std::getline(data, name);
name = trim(name);
set_name = true;
} else if (ident == "display_name:") {
std::getline(data, display_name);
display_name = trim(display_name);
} else if (ident == "plural:") {
std::getline(data, plural_name);
plural_name = trim(plural_name);
} else if (ident == "description:") {
std::string desc;
description = "";
while (no_caps(desc) != "done") {
std::getline(data, desc);
desc = trim(desc);
if (no_caps(desc) != "done") {
description = description + " " + desc;
}
}
description = trim(description); // Get rid of extra " "
} else if (ident == "glyph:") {
sym.load_data_text(data, name);
std::getline(data, junk);
set_glyph = true;
} else if (ident == "weight:") {
data >> weight;
std::getline(data, junk);
} else if (ident == "volume:") {
data >> volume;
std::getline(data, junk);
} else if (ident == "bash:") {
data >> damage[DAMAGE_BASH];
std::getline(data, junk);
} else if (ident == "cut:") {
data >> damage[DAMAGE_CUT];
std::getline(data, junk);
} else if (ident == "pierce:") {
data >> damage[DAMAGE_PIERCE];
std::getline(data, junk);
} else if (ident == "to_hit:") {
data >> to_hit;
std::getline(data, junk);
} else if (ident == "speed:" || ident == "attack_speed:") {
data >> attack_speed;
std::getline(data, junk);
} else if (ident == "thrown_variance:") {
if (!thrown_variance.load_data(data, name)) {
return false;
}
} else if (ident == "thrown_dmg_percent:") {
data >> thrown_dmg_percent;
std::getline(data, junk);
} else if (ident == "thrown_speed:") {
data >> thrown_speed;
std::getline(data, junk);
} else if (ident == "mission_xp:") {
data >> mission_experience;
std::getline(data, junk);
} else if (ident == "container:") {
std::getline(data, container);
container = no_caps(container);
container = trim(container);
if (container.empty()) {
debugmsg("Empty container (%s)", name.c_str());
return false;
}
} else if (ident == "flags:") {
std::string flag_line;
std::getline(data, flag_line);
std::istringstream flag_data(flag_line);
std::string flag_name;
while (flag_data >> flag_name) {
Item_flag flag = lookup_item_flag(flag_name);
if (flag == ITEM_FLAG_NULL) {
debugmsg("Unknown item flag '%s' (%s)",
flag_name.c_str(), name.c_str());
return false;
}
flags[flag] = true;
}
} else if (ident != "done" && !handle_data(ident, data)) {
debugmsg("Unknown Item_type flag '%s' (%s)", ident.c_str(), name.c_str());
return false;
}
}
// Ensure that we set a glyph and name!
if (!set_name) {
debugmsg("Item created without a name!");
return false;
}
if (!set_glyph) {
debugmsg("Item '%s' created without a glyph!", name.c_str());
return false;
}
return true;
}
bool Item_type::handle_data(std::string ident, std::istream &data)
{
if (ident == "done") {
return true;
}
return false;
}
bool Item_type::has_flag(Item_flag flag)
{
return flags[flag];
}
/* TODO: Right now, armor{_bash,_cut,_pierce} is hard-coded here. But what if
* we add a damage type and want to protect against it with armor? We
* should generalize and look up damage type names instead.
*/
bool Item_type_clothing::handle_data(std::string ident, std::istream &data)
{
std::string junk;
if (ident == "carries:") {
data >> carry_capacity;
std::getline(data, junk);
} else if (ident == "armor_bash:") {
data >> armor_bash;
std::getline(data, junk);
} else if (ident == "armor_cut:") {
data >> armor_cut;
std::getline(data, junk);
} else if (ident == "armor_pierce:") {
data >> armor_pierce;
std::getline(data, junk);
} else if (ident == "protection:") {
data >> protection;
std::getline(data, junk);
} else if (ident == "encumbrance:") {
data >> encumbrance;
std::getline(data, junk);
} else if (ident == "covers:") {
std::string line;
std::getline(data, line);
std::istringstream cover_data(line);
std::string body_part_name;
while (cover_data >> body_part_name) {
std::vector<Body_part> parts = get_body_part_list( body_part_name );
for (int i = 0; i < parts.size(); i++) {
covers[ parts[i] ] = true;
}
if (parts.empty()) {
debugmsg("Unknown body part '%s' (%s)", body_part_name.c_str(),
name.c_str());
return false;
}
}
} else if (ident != "done") {
return false;
}
return true;
}
bool Item_type_ammo::handle_data(std::string ident, std::istream &data)
{
std::string junk;
if (ident == "type:") {
std::getline(data, ammo_type);
} else if (ident == "damage:") {
data >> damage;
std::getline(data, junk);
} else if (ident == "armor_pierce:" || ident == "pierce:") {
data >> armor_pierce;
if (armor_pierce <= 0) {
armor_pierce = 10;
}
std::getline(data, junk);
} else if (ident == "range:") {
data >> range;
std::getline(data, junk);
} else if (ident == "accuracy:") {
if (!accuracy.load_data(data, name)) {
return false;
}
} else if (ident == "count:") {
data >> count;
std::getline(data, junk);
} else if (ident == "pellets:") {
data >> pellets;
std::getline(data, junk);
} else if (ident != "done") {
return false;
}
return true;
}
bool Item_type_launcher::handle_data(std::string ident, std::istream &data)
{
std::string junk;
if (ident == "type:" || ident == "ammo_type:") {
std::getline(data, ammo_type);
} else if (ident == "skill:") {
std::string skill_name;
std::getline(data, skill_name);
skill_used = lookup_skill_type(skill_name);
if (skill_used == SKILL_NULL) {
debugmsg("No such skill as '%s' (%s)", skill_name.c_str(), name.c_str());
return false;
}
} else if (ident == "damage:") {
data >> damage;
std::getline(data, junk);
} else if (ident == "accuracy:") {
if (!accuracy.load_data(data, name)) {
return false;
}
} else if (ident == "recoil:") {
data >> recoil;
std::getline(data, junk);
} else if (ident == "durability:") {
data >> durability;
std::getline(data, junk);
// "Clip" and "magazine" to satisfy the gun nerds. what up gun nerds
} else if (ident == "clip:" || ident == "magazine:" || ident == "capacity:") {
data >> capacity;
std::getline(data, junk);
} else if (ident == "reload_time:" || ident == "reload_ap:") {
data >> reload_ap;
std::getline(data, junk);
} else if (ident == "fire_time:" || ident == "fire_ap:") {
data >> fire_ap;
std::getline(data, junk);
} else if (ident == "modes:" || ident == "mode:") {
std::string mode_line;
std::getline(data, mode_line);
std::istringstream mode_ss(mode_line);
int mode;
while (mode_ss >> mode) {
modes.push_back(mode);
}
} else if (ident != "done") {
return false;
}
return true;
}
bool Item_type_food::handle_data(std::string ident, std::istream &data)
{
std::string junk;
if (ident == "food:") {
data >> food;
std::getline(data, junk);
} else if (ident == "water:") {
data >> water;
std::getline(data, junk);
} else if (ident == "effect_chance:") {
data >> effect_chance;
std::getline(data, junk);
if (effect_chance <= 0) {
debugmsg("Food effect_chance of %d corrected to 1 (%s)",
effect_chance, name.c_str());
effect_chance = 1;
} else if (effect_chance > 100) {
debugmsg("Food effect_chance of %d corrected to 100 (%s)",
effect_chance, name.c_str());
effect_chance = 100;
}
} else if (ident == "effect:") {
if (!effect.load_data(data, name)) {
return false;
}
} else if (ident == "charges:") {
data >> charges;
std::getline(data, junk);
} else if (ident == "verb:") {
std::getline(data, verb);
verb = no_caps(verb);
verb = trim(verb);
if (verb.empty()) {
debugmsg("Empty verb (%s)", name.c_str());
return false;
}
} else if (ident != "done") {
return false;
}
return true;
}
bool Item_type_tool::handle_data(std::string ident, std::istream &data)
{
std::string junk;
if (ident == "applied:") {
if (!applied_action.load_data(data, name)) {
return false;
}
} else if (ident == "powered:") {
if (!powered_action.load_data(data, name)) {
return false;
}
} else if (ident == "countdown:") {
if (!countdown_action.load_data(data, name)) {
return false;
}
} else if (ident == "countdown_timer:") {
data >> countdown_timer;
std::getline(data, junk);
} else if (ident == "def_charges:" || ident == "default_charges:") {
data >> def_charges;
std::getline(data, junk);
} else if (ident == "max_charges:") {
data >> max_charges;
std::getline(data, junk);
} else if (ident == "subcharges:") {
data >> subcharges;
std::getline(data, junk);
} else if (ident == "fuel:") {
std::getline(data, fuel);
fuel = no_caps(fuel);
fuel = trim(fuel);
} else if (ident == "powered_text:") {
std::getline(data, powered_text);
powered_text = no_caps(powered_text);
powered_text = trim(powered_text);
} else if (ident != "done") {
debugmsg("Unknown Tool property '%s' (%s)", ident.c_str(), name.c_str());
return false;
}
return true;
}
bool Item_type_tool::uses_charges()
{
return (max_charges > 0);
}
Item_type_book::Item_type_book()
{
skill_learned = SKILL_NULL;
genre = GENRE_NULL;
cap_limit = 0;
int_required = 0;
skill_required = 0;
high_int_bonus = 0;
bonus_int_required = 0;
fun = 0;
chapters = 1;
}
std::string Item_type_book::get_name_singular()
{
std::stringstream ret;
ret << "copy of \"" << get_name() << "\"";
return ret.str();
}
std::string Item_type_book::get_name_plural()
{
std::stringstream ret;
ret << "copies of \"" << get_name() << "\"";
return ret.str();
}
std::string Item_type_book::get_property_description()
{
std::stringstream ret;
if (genre != GENRE_NULL) {
ret << "<c=cyan>Genre: " << book_genre_name(genre) << "<c=/>" <<
std::endl;
}
ret << "<c=magenta>Intelligence required:<c=/> " << int_required << std::endl;
ret << "<c=brown>Time to read: ";
if (time_to_read() < 5) {
ret << "<c=white>";
} else if (time_to_read() < 30) {
ret << "<c=yellow>";
} else {
ret << "<c=ltred>";
}
ret << time_to_read() << " minutes<c=/>" << std::endl;
if (skill_learned == SKILL_NULL) {
ret << "<c=dkgray>No related skill.<c=/>" << std::endl;
} else {
ret << "<c=white>Increases your " << skill_type_user_name(skill_learned) <<
" skill cap to <c=ltblue>" << cap_limit << "<c=/>." << std::endl;
if (high_int_bonus > 0) {
ret << "<c=white>With intelligence <c=magenta>" << bonus_int_required <<
"<c=white>, increases your skill cap to <c=ltblue>" <<
high_int_bonus + cap_limit << "<c=/>." << std::endl;
}
if (skill_required > 0) {
ret << "<c=ltred>" << skill_type_user_name(skill_learned) << " level " <<
"required: " << skill_required;
}
}
if (fun < 0) {
ret << "<c=ltred>Morale lost:<c=ltgray> " << 0 - fun << std::endl;
} else if (fun > 0) {
ret << "<c=ltgreen>Morale gained:<c=ltgray> " << fun << std::endl <<
"<c=white>Chapters:<c=ltgray> " << chapters << std::endl;
}
return ret.str();
}
int Item_type_book::time_to_read()
{
if (skill_learned == SKILL_NULL) { // It's just a fun book - reads faster
return 15 + int_required; // More complex books read slower.
}
return cap_limit * 5 + int_required * 2;
}
bool Item_type_book::handle_data(std::string ident, std::istream& data)
{
std::string junk;
if (ident == "skill:") {
std::string skill_name;
std::getline(data, skill_name);
skill_learned = lookup_skill_type(skill_name);
if (skill_learned == SKILL_NULL) {
debugmsg("Unknown Skill_type '%s' (%s).",
skill_name.c_str(), name.c_str());
return false;
}
} else if (ident == "genre:") {
std::string genre_name;
std::getline(data, genre_name);
genre = lookup_book_genre(genre_name);
if (genre == GENRE_NULL) {
debugmsg("Unknown Book_genre '%s' (%s).",
genre_name.c_str(), name.c_str());
return false;
}
} else if (ident == "cap:") {
data >> cap_limit;
std::getline(data, junk);
} else if (ident == "int_required:") {
data >> int_required;
std::getline(data, junk);
} else if (ident == "skill_required:") {
data >> skill_required;
std::getline(data, junk);
} else if (ident == "high_int_bonus:") {
data >> high_int_bonus;
std::getline(data, junk);
} else if (ident == "bonus_int_required:") {
data >> bonus_int_required;
std::getline(data, junk);
} else if (ident == "fun:") {
data >> fun;
std::getline(data, junk);
} else if (ident == "chapters:") {
data >> chapters;
std::getline(data, junk);
} else if (ident != "done") {
return false;
}
return true;
}
Item_type_container::Item_type_container()
{
capacity = 0;
preposition = "of";
use_article = false;
}
std::string Item_type_container::get_property_description()
{
std::stringstream ret;
ret << "<c=white>Capacity:<c=/> " << capacity;
return ret.str();
}
bool Item_type_container::handle_data(std::string ident, std::istream &data)
{
std::string junk;
if (ident == "capacity:") {
data >> capacity;
std::getline(data, junk);
} else if (ident == "preposition:") {
std::getline(data, preposition);
preposition = no_caps(preposition);
preposition = trim(preposition);
} else if (ident == "use_article" || ident == "use_article:") {
use_article = true;
} else if (ident != "done") {
debugmsg("Unknown Container property '%s' (%s)",
ident.c_str(), name.c_str());
return false;
}
return true;
}
// Item_type_corpse doesn't have any properties, so this section is boring.
Item_type_corpse::Item_type_corpse()
{
}
bool Item_type_corpse::handle_data(std::string ident, std::istream& data)
{
if (ident != "done") {
debugmsg("Data in corpse definition - corpse doesn't have data!");
return false;
}
return true;
}
Item_class lookup_item_class(std::string name)
{
name = no_caps(name);
for (int i = 0; i < ITEM_CLASS_MAX; i++) {
Item_class ret = Item_class(i);
if ( no_caps( item_class_name(ret) ) == name ) {
return ret;
}
}
return ITEM_CLASS_MISC;
}
std::string item_class_name_plural(Item_class iclass)
{
return item_class_name(iclass, true);
}
// plural defaults to false
std::string item_class_name(Item_class iclass, bool plural)
{
switch (iclass) {
case ITEM_CLASS_MISC: return "Misc";
case ITEM_CLASS_CLOTHING: return "Clothing";
case ITEM_CLASS_AMMO: return "Ammo";
case ITEM_CLASS_LAUNCHER: return (plural ? "Launchers" : "Launcher" );
case ITEM_CLASS_FOOD: return "Food";
case ITEM_CLASS_TOOL: return (plural ? "Tools" : "Tool" );
case ITEM_CLASS_BOOK: return (plural ? "Books" : "Book" );
case ITEM_CLASS_CONTAINER: return (plural ? "Containers" : "Container" );
case ITEM_CLASS_CORPSE: return (plural ? "Corpses" : "Corpse" );
case ITEM_CLASS_MAX: return "BUG - ITEM_CLASS_MAX";
default: return "BUG - Unnamed Item_class";
}
return "BUG - Escaped item_class_name switch";
}
Item_flag lookup_item_flag(std::string name)
{
name = no_caps(name);
for (int i = 0; i < ITEM_FLAG_MAX; i++) {
Item_flag ret = Item_flag(i);
if ( no_caps( item_flag_name(ret) ) == name ) {
return ret;
}
}
return ITEM_FLAG_NULL;
}
std::string item_flag_name(Item_flag flag)
{
switch (flag) {
case ITEM_FLAG_NULL: return "NULL";
case ITEM_FLAG_LIQUID: return "liquid";
case ITEM_FLAG_FLAMMABLE: return "flammable";
case ITEM_FLAG_PLURAL: return "plural";
case ITEM_FLAG_CONSTANT: return "constant_volume_weight";
case ITEM_FLAG_RELOAD_SINGLE: return "reload_single";
case ITEM_FLAG_OPEN_END: return "open_end";
case ITEM_FLAG_GLASSES: return "glasses";
case ITEM_FLAG_RELOAD_STR: return "reload_strength";
case ITEM_FLAG_MAX: return "BUG - ITEM_FLAG_MAX";
default: return "BUG - Unnamed Item_flag";
}
return "BUG - Escaped item_flag_name switch";
}
Book_genre lookup_book_genre(std::string name)
{
name = no_caps( trim( name ) );
for (int i = 0; i < GENRE_MAX; i++) {
Book_genre ret = Book_genre(i);
if (name == no_caps( book_genre_name(ret) )) {
return ret;
}
}
return GENRE_NULL;
}
std::string book_genre_name(Book_genre genre)
{
switch (genre) {
case GENRE_NULL: return "NULL";
case GENRE_AUTOBIOGRAPHY: return "autobiography";
case GENRE_HISTORY: return "history";
case GENRE_NOVEL: return "novel";
case GENRE_SCIFI: return "scifi";
case GENRE_FANTASY: return "fantasy";
case GENRE_MYSTERY: return "mystery";
case GENRE_ROMANCE: return "romance";
case GENRE_MAX: return "ERROR - GENRE_MAX";
default: return "ERROR - Unnamed Book_genre";
}
return "ERROR - Escaped book_genre_name() switch";
}