forked from CleverRaven/Cataclysm-DDA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
item.cpp
1888 lines (1648 loc) · 49 KB
/
item.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
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "item.h"
#include "player.h"
#include "output.h"
#include "skill.h"
#include "game.h"
#include <sstream>
#include "cursesdef.h"
bool is_flammable(material m);
std::string default_technique_name(technique_id tech);
item::item()
{
name = "";
charges = -1;
bday = 0;
invlet = 0;
damage = 0;
burnt = 0;
poison = 0;
mode = IF_NULL;
type = nullitem();
curammo = NULL;
corpse = NULL;
active = false;
owned = -1;
mission_id = -1;
player_id = -1;
}
item::item(itype* it, unsigned int turn)
{
if(!it)
type = nullitem();
else
type = it;
bday = turn;
name = "";
invlet = 0;
damage = 0;
burnt = 0;
poison = 0;
mode = IF_NULL;
active = false;
curammo = NULL;
corpse = NULL;
owned = -1;
mission_id = -1;
player_id = -1;
if (it == NULL)
return;
if (it->is_gun())
charges = 0;
else if (it->is_ammo()) {
it_ammo* ammo = dynamic_cast<it_ammo*>(it);
charges = ammo->count;
} else if (it->is_food()) {
it_comest* comest = dynamic_cast<it_comest*>(it);
if (comest->charges == 1 && !made_of(LIQUID))
charges = -1;
else
charges = comest->charges;
} else if (it->is_tool()) {
it_tool* tool = dynamic_cast<it_tool*>(it);
if (tool->max_charges == 0)
charges = -1;
else
charges = tool->def_charges;
} else if (it->is_gunmod() && it->id == itm_spare_mag) {
charges = 0;
} else
charges = -1;
if(it->is_var_veh_part()){
it_var_veh_part* varcarpart = dynamic_cast<it_var_veh_part*>(it);
bigness= rng( varcarpart->min_bigness, varcarpart->max_bigness);
}
}
item::item(itype *it, unsigned int turn, char let)
{
if(!it)
type = nullitem();
else
type = it;
bday = turn;
name = "";
damage = 0;
burnt = 0;
poison = 0;
mode = IF_NULL;
active = false;
if (it->is_gun()) {
charges = 0;
} else if (it->is_ammo()) {
it_ammo* ammo = dynamic_cast<it_ammo*>(it);
charges = ammo->count;
} else if (it->is_food()) {
it_comest* comest = dynamic_cast<it_comest*>(it);
if (comest->charges == 1 && !made_of(LIQUID))
charges = -1;
else
charges = comest->charges;
} else if (it->is_tool()) {
it_tool* tool = dynamic_cast<it_tool*>(it);
if (tool->max_charges == 0)
charges = -1;
else
charges = tool->def_charges;
} else if (it->is_gunmod() && it->id == itm_spare_mag) {
charges = 0;
} else {
charges = -1;
}
if(it->is_var_veh_part()){
it_var_veh_part* engine = dynamic_cast<it_var_veh_part*>(it);
bigness= rng( engine->min_bigness, engine->max_bigness);
}
curammo = NULL;
corpse = NULL;
owned = -1;
invlet = let;
mission_id = -1;
player_id = -1;
}
void item::make_corpse(itype* it, mtype* mt, unsigned int turn)
{
name = "";
charges = -1;
invlet = 0;
damage = 0;
burnt = 0;
poison = 0;
mode = IF_NULL;
curammo = NULL;
active = false;
if(!it)
type = nullitem();
else
type = it;
corpse = mt;
bday = turn;
}
itype * item::nullitem_m = new itype();
itype * item::nullitem()
{
return nullitem_m;
}
item::item(std::string itemdata, game *g)
{
load_info(itemdata, g);
}
item::~item()
{
}
void item::make(itype* it)
{
if(!it)
type = nullitem();
else
type = it;
contents.clear();
}
bool item::is_null()
{
return (type == NULL || type->id == 0);
}
item item::in_its_container(std::vector<itype*> *itypes)
{
if (is_software()) {
item ret( (*itypes)[itm_usb_drive], 0);
ret.contents.push_back(*this);
ret.invlet = invlet;
return ret;
}
if (!is_food() || (dynamic_cast<it_comest*>(type))->container == itm_null)
return *this;
it_comest *food = dynamic_cast<it_comest*>(type);
item ret((*itypes)[food->container], bday);
if (dynamic_cast<it_comest*>(type)->container == itm_can_food)
food->spoils = 0;
if (made_of(LIQUID))
{
it_container* container = dynamic_cast<it_container*>(ret.type);
charges = container->contains * food->charges;
}
ret.contents.push_back(*this);
ret.invlet = invlet;
return ret;
}
bool item::invlet_is_okay()
{
return ((invlet >= 'a' && invlet <= 'z') || (invlet >= 'A' && invlet <= 'Z'));
}
bool item::stacks_with(item rhs)
{
bool stacks = (type == rhs.type && damage == rhs.damage &&
active == rhs.active && charges == rhs.charges &&
contents.size() == rhs.contents.size() &&
(!goes_bad() || bday == rhs.bday));
if ((corpse == NULL && rhs.corpse != NULL) ||
(corpse != NULL && rhs.corpse == NULL) )
return false;
if (corpse != NULL && rhs.corpse != NULL &&
corpse->id != rhs.corpse->id)
return false;
if (contents.size() != rhs.contents.size())
return false;
if(is_var_veh_part())
if(bigness != rhs.bigness)
return false;
for (int i = 0; i < contents.size() && stacks; i++)
stacks &= contents[i].stacks_with(rhs.contents[i]);
return stacks;
}
void item::put_in(item payload)
{
contents.push_back(payload);
}
std::string item::save_info()
{
if (type == NULL)
debugmsg("Tried to save an item with NULL type!");
int ammotmp = 0;
/* TODO: This causes a segfault sometimes, even though we check to make sure
* curammo isn't NULL. The crashes seem to occur most frequently when saving an
* NPC, or when saving map data containing an item an NPC has dropped.
*/
if (curammo != NULL)
ammotmp = curammo->id;
if (ammotmp < 0 || ammotmp > num_items)
ammotmp = 0; // Saves us from some bugs
std::stringstream dump;// (std::stringstream::in | std::stringstream::out);
dump << " " << int(invlet) << " " << int(typeId()) << " " << int(charges) <<
" " << int(damage) << " " << int(burnt) << " " << poison << " " <<
ammotmp << " " << owned << " " << int(bday);
if (active)
dump << " 1";
else
dump << " 0";
if (corpse != NULL)
dump << " " << corpse->id;
else
dump << " -1";
dump << " " << mission_id << " " << player_id;
size_t pos = name.find_first_of("\n");
while (pos != std::string::npos) {
name.replace(pos, 1, "@@");
pos = name.find_first_of("\n");
}
dump << " '" << name << "'";
return dump.str();
}
void item::load_info(std::string data, game *g)
{
std::stringstream dump;
dump << data;
int idtmp, ammotmp, lettmp, damtmp, burntmp, acttmp, corp;
dump >> lettmp >> idtmp >> charges >> damtmp >> burntmp >> poison >> ammotmp >>
owned >> bday >> acttmp >> corp >> mission_id >> player_id;
if (corp != -1)
corpse = g->mtypes[corp];
else
corpse = NULL;
getline(dump, name);
if (name == " ''")
name = "";
else {
size_t pos = name.find_first_of("@@");
while (pos != std::string::npos) {
name.replace(pos, 2, "\n");
pos = name.find_first_of("@@");
}
name = name.substr(2, name.size() - 3); // s/^ '(.*)'$/\1/
}
make(g->itypes[idtmp]);
invlet = char(lettmp);
damage = damtmp;
burnt = burntmp;
active = false;
mode = IF_NULL;
if (acttmp == 1)
active = true;
if (ammotmp > 0)
curammo = dynamic_cast<it_ammo*>(g->itypes[ammotmp]);
else
curammo = NULL;
}
std::string item::info(bool showtext)
{
std::vector<iteminfo> dummy;
return info(showtext, &dummy);
}
std::string item::info(bool showtext, std::vector<iteminfo> *dump)
{
std::stringstream temp1, temp2;
if( !is_null() )
{
dump->push_back(iteminfo("BASE", " Volume: ", "", int(volume()), "", false, true));
dump->push_back(iteminfo("BASE", " Weight: ", "", int(weight()), "", true, true));
dump->push_back(iteminfo("BASE", " Bash: ", "", int(type->melee_dam), "", false));
dump->push_back(iteminfo("BASE", (has_flag(IF_SPEAR) ? " Pierce: " : " Cut: "), "", int(type->melee_cut), "", false));
dump->push_back(iteminfo("BASE", " To-hit bonus: ", ((type->m_to_hit > 0) ? "+" : ""), int(type->m_to_hit), ""));
dump->push_back(iteminfo("BASE", " Moves per attack: ", "", int(attack_time()), "", true, true));
/*
dump << " Volume: " << volume() << " Weight: " << weight() << "\n" <<
" Bash: " << int(type->melee_dam) <<
(has_flag(IF_SPEAR) ? " Pierce: " : " Cut: ") <<
int(type->melee_cut) << " To-hit bonus: " <<
(type->m_to_hit > 0 ? "+" : "" ) << int(type->m_to_hit) << "\n" <<
" Moves per attack: " << attack_time() << "\n";
*/
}
if (is_food()) {
it_comest* food = dynamic_cast<it_comest*>(type);
dump->push_back(iteminfo("FOOD", " Nutrition: ", "", int(food->nutr)));
dump->push_back(iteminfo("FOOD", " Quench: ", "", int(food->quench)));
dump->push_back(iteminfo("FOOD", " Enjoyability: ", "", int(food->fun)));
/*
dump << " Nutrition: " << int(food->nutr) << "\n Quench: " <<
int(food->quench) << "\n Enjoyability: " << int(food->fun);
*/
} else if (is_food_container()) {
// added charge display for debugging
it_comest* food = dynamic_cast<it_comest*>(contents[0].type);
dump->push_back(iteminfo("FOOD", " Nutrition: ", "", int(food->nutr)));
dump->push_back(iteminfo("FOOD", " Quench: ", "", int(food->quench)));
dump->push_back(iteminfo("FOOD", " Enjoyability: ", "", int(food->fun)));
dump->push_back(iteminfo("FOOD", " Charges: ", "", int(contents[0].charges)));
/*
dump << " Nutrition: " << int(food->nutr) << "\n Quench: " <<
int(food->quench) << "\n Enjoyability: " << int(food->fun)
<< "\n Charges: " << int(contents[0].charges);
*/
} else if (is_ammo()) {
// added charge display for debugging
it_ammo* ammo = dynamic_cast<it_ammo*>(type);
dump->push_back(iteminfo("AMMO", " Type: ", ammo_name(ammo->type)));
dump->push_back(iteminfo("AMMO", " Damage: ", "", int(ammo->damage)));
dump->push_back(iteminfo("AMMO", " Armor-pierce: ", "", int(ammo->pierce)));
dump->push_back(iteminfo("AMMO", " Range: ", "", int(ammo->range)));
dump->push_back(iteminfo("AMMO", " Accuracy: ", "", int(100 - ammo->accuracy)));
dump->push_back(iteminfo("AMMO", " Recoil: ", "", int(ammo->recoil), "", true, true));
dump->push_back(iteminfo("AMMO", " Count: ", "", int(ammo->count)));
/*
dump << " Type: " << ammo_name(ammo->type) << "\n Damage: " <<
int(ammo->damage) << "\n Armor-pierce: " << int(ammo->pierce) <<
"\n Range: " << int(ammo->range) << "\n Accuracy: " <<
int(100 - ammo->accuracy) << "\n Recoil: " << int(ammo->recoil)
<< "\n Count: " << int(ammo->count);
*/
} else if (is_ammo_container()) {
it_ammo* ammo = dynamic_cast<it_ammo*>(contents[0].type);
dump->push_back(iteminfo("AMMO", " Type: ", ammo_name(ammo->type)));
dump->push_back(iteminfo("AMMO", " Damage: ", "", int(ammo->damage)));
dump->push_back(iteminfo("AMMO", " Armor-pierce: ", "", int(ammo->pierce)));
dump->push_back(iteminfo("AMMO", " Range: ", "", int(ammo->range)));
dump->push_back(iteminfo("AMMO", " Accuracy: ", "", int(100 - ammo->accuracy)));
dump->push_back(iteminfo("AMMO", " Recoil: ", "", int(ammo->recoil), "", true, true));
dump->push_back(iteminfo("AMMO", " Count: ", "", int(contents[0].charges)));
/*
dump << " Type: " << ammo_name(ammo->type) << "\n Damage: " <<
int(ammo->damage) << "\n Armor-pierce: " << int(ammo->pierce) <<
"\n Range: " << int(ammo->range) << "\n Accuracy: " <<
int(100 - ammo->accuracy) << "\n Recoil: " << int(ammo->recoil)
<< "\n Count: " << int(contents[0].charges);
*/
} else if (is_gun()) {
it_gun* gun = dynamic_cast<it_gun*>(type);
int ammo_dam = 0, ammo_recoil = 0;
bool has_ammo = (curammo != NULL && charges > 0);
if (has_ammo) {
ammo_dam = curammo->damage;
ammo_recoil = curammo->recoil;
}
dump->push_back(iteminfo("GUN", " Skill used: ", gun->skill_used->name()));
dump->push_back(iteminfo("GUN", " Ammunition: ", "", int(clip_size()), " rounds of " + ammo_name(ammo_type())));
/*
dump << " Skill used: " << gun->skill_used->name() << "\n Ammunition: " <<
clip_size() << " rounds of " << ammo_name(ammo_type());
dump << "\n Damage: ";
*/
temp1.str("");
if (has_ammo)
temp1 << ammo_dam; //dump << ammo_dam;
temp1 << (gun_damage(false) >= 0 ? "+" : "" );
//dump << (gun_damage(false) >= 0 ? "+" : "" ) << gun_damage(false);
temp2.str("");
if (has_ammo)
temp2 << " = " << gun_damage(); //dump << " = " << gun_damage();
dump->push_back(iteminfo("GUN", " Damage: ", temp1.str(), int(gun_damage(false)), temp2.str()));
dump->push_back(iteminfo("GUN", " Accuracy: ", "", int(100 - accuracy())));
//dump << "\n Accuracy: " << int(100 - accuracy());
//dump << "\n Recoil: ";
temp1.str("");
if (has_ammo)
temp1 << ammo_recoil; //dump << ammo_recoil;
temp1 << (recoil(false) >= 0 ? "+" : "" );
//dump << (recoil(false) >= 0 ? "+" : "" ) << recoil(false);
temp2.str("");
if (has_ammo)
temp2 << " = " << recoil(); //dump << " = " << recoil();
dump->push_back(iteminfo("GUN"," Recoil: ", temp1.str(), int(recoil(false)), temp2.str(), true, true));
//dump << "\n Reload time: " << int(gun->reload_time);
//if (has_flag(IF_RELOAD_ONE))
//dump << " per round";
dump->push_back(iteminfo("GUN", " Reload time: ", "", int(gun->reload_time), ((has_flag(IF_RELOAD_ONE)) ? " per round" : ""), true, true));
if (burst_size() == 0) {
if (gun->skill_used == Skill::skill("pistol") && has_flag(IF_RELOAD_ONE))
dump->push_back(iteminfo("GUN", " Revolver.")); //dump << "\n Revolver.";
else
dump->push_back(iteminfo("GUN", " Semi-automatic.")); //dump << "\n Semi-automatic.";
} else
dump->push_back(iteminfo("GUN", " Burst size: ", "", int(burst_size()))); //dump << "\n Burst size: " << burst_size();
if (contents.size() > 0)
dump->push_back(iteminfo("GUN", "\n")); //dump << "\n";
temp1.str("");
for (int i = 0; i < contents.size(); i++)
temp1 << "\n+" << contents[i].tname();
dump->push_back(iteminfo("GUN", temp1.str())); //
} else if (is_gunmod()) {
it_gunmod* mod = dynamic_cast<it_gunmod*>(type);
if (mod->accuracy != 0)
dump->push_back(iteminfo("GUNMOD", " Accuracy: ", ((mod->accuracy > 0) ? "+" : ""), int(mod->accuracy))); //dump << " Accuracy: " << (mod->accuracy > 0 ? "+" : "") << int(mod->accuracy);
if (mod->damage != 0)
dump->push_back(iteminfo("GUNMOD", " Damage: ", ((mod->damage > 0) ? "+" : ""), int(mod->damage))); //dump << "\n Damage: " << (mod->damage > 0 ? "+" : "") << int(mod->damage);
if (mod->clip != 0)
dump->push_back(iteminfo("GUNMOD", " Magazine: ", ((mod->clip > 0) ? "+" : ""), int(mod->clip), "%")); //dump << "\n Magazine: " << (mod->clip > 0 ? "+" : "") << int(mod->damage) << "%";
if (mod->recoil != 0)
dump->push_back(iteminfo("GUNMOD", " Recoil: ", ((mod->recoil > 0) ? "+" : ""), int(mod->recoil), "", true, true)); //dump << "\n Recoil: " << int(mod->recoil);
if (mod->burst != 0)
dump->push_back(iteminfo("GUNMOD", " Burst: ", (mod->burst > 0 ? "+" : ""), int(mod->burst))); //dump << "\n Burst: " << (mod->clip > 0 ? "+" : "") << int(mod->clip);
if (mod->newtype != AT_NULL)
dump->push_back(iteminfo("GUNMOD", " " + ammo_name(mod->newtype))); //dump << "\n " << ammo_name(mod->newtype);
temp1.str("");
temp1 << " Used on: ";
if (mod->used_on_pistol)
temp1 << "Pistols. ";
if (mod->used_on_shotgun)
temp1 << "Shotguns. ";
if (mod->used_on_smg)
temp1 << "SMGs. ";
if (mod->used_on_rifle)
temp1 << "Rifles.";
dump->push_back(iteminfo("GUNMOD", temp1.str()));
} else if (is_armor()) {
it_armor* armor = dynamic_cast<it_armor*>(type);
temp1.str("");
temp1 << " Covers: ";
if (armor->covers & mfb(bp_head))
temp1 << "The head. ";
if (armor->covers & mfb(bp_eyes))
temp1 << "The eyes. ";
if (armor->covers & mfb(bp_mouth))
temp1 << "The mouth. ";
if (armor->covers & mfb(bp_torso))
temp1 << "The torso. ";
if (armor->covers & mfb(bp_arms))
temp1 << "The arms. ";
if (armor->covers & mfb(bp_hands))
temp1 << "The hands. ";
if (armor->covers & mfb(bp_legs))
temp1 << "The legs. ";
if (armor->covers & mfb(bp_feet))
temp1 << "The feet. ";
dump->push_back(iteminfo("ARMOR", temp1.str()));
dump->push_back(iteminfo("ARMOR", " Encumberment: ", "", int(armor->encumber), "", true, true));
dump->push_back(iteminfo("ARMOR", " Bashing protection: ", "", int(armor->dmg_resist)));
dump->push_back(iteminfo("ARMOR", " Cut protection: ", "", int(armor->cut_resist)));
dump->push_back(iteminfo("ARMOR", " Environmental protection: ", "", int(armor->env_resist)));
dump->push_back(iteminfo("ARMOR", " Warmth: ", "", int(armor->warmth)));
dump->push_back(iteminfo("ARMOR", " Storage: ", "", int(armor->storage)));
/*
dump << "\n Encumberment: " << int(armor->encumber) <<
"\n Bashing protection: " << int(armor->dmg_resist) <<
"\n Cut protection: " << int(armor->cut_resist) <<
"\n Environmental protection: " << int(armor->env_resist) <<
"\n Warmth: " << int(armor->warmth) <<
"\n Storage: " << int(armor->storage);
*/
} else if (is_book()) {
it_book* book = dynamic_cast<it_book*>(type);
if (!book->type)
dump->push_back(iteminfo("BOOK", " Just for fun.")); //dump << " Just for fun.\n";
else {
dump->push_back(iteminfo("BOOK", " Can bring your ", book->type->name() + " skill to ", int(book->level)));
//dump << " Can bring your " << book->type->name() << " skill to " << int(book->level) << std::endl;
if (book->req == 0)
dump->push_back(iteminfo("BOOK", " It can be understood by beginners.")); //dump << " It can be understood by beginners.\n";
else
dump->push_back(iteminfo("BOOK", " Requires ", book->type->name() + " level ", int(book->req), " to understand.", true, true)); //dump << " Requires " << book->type->name() << " level " << int(book->req) << " to understand.\n";
}
dump->push_back(iteminfo("BOOK", " Requires intelligence of ", "", int(book->intel), " to easily read.", true, true));
//dump << " Requires intelligence of " << int(book->intel) << " to easily read." << std::endl;
if (book->fun != 0)
dump->push_back(iteminfo("BOOK", " Reading this book affects your morale by ", (book->fun > 0 ? "+" : ""), int(book->fun))); //dump << " Reading this book affects your morale by " << (book->fun > 0 ? "+" : "") << int(book->fun) << std::endl;
dump->push_back(iteminfo("BOOK", " This book takes ", "", int(book->time), " minutes to read.", true, true));
//dump << " This book takes " << int(book->time) << " minutes to read.";
} else if (is_tool()) {
it_tool* tool = dynamic_cast<it_tool*>(type);
/*
dump << " Maximum " << tool->max_charges << " charges";
if (tool->ammo == AT_NULL)
dump << ".";
else
dump << " of " << ammo_name(tool->ammo) << ".";
*/
dump->push_back(iteminfo("TOOL", " Maximum ", "", int(tool->max_charges), " charges" + ((tool->ammo == AT_NULL) ? "" : (" of " + ammo_name(tool->ammo))) + "."));
} else if (is_style()) {
it_style* style = dynamic_cast<it_style*>(type);
//dump << "\n";
for (int i = 0; i < style->moves.size(); i++) {
dump->push_back(iteminfo("STYLE", default_technique_name(style->moves[i].tech), ". Requires Unarmed Skill of ", int(style->moves[i].level)));
//dump << default_technique_name(style->moves[i].tech) << ". Requires Unarmed Skill of " << style->moves[i].level << "\n";
}
} else if (!is_null() && type->techniques != 0) {
//dump << "\n";
temp1.str("");
for (int i = 1; i < NUM_TECHNIQUES; i++) {
if (type->techniques & mfb(i))
temp1 << default_technique_name( technique_id(i) ) + "; "; //dump << default_technique_name( technique_id(i) ) << "; ";
}
if (temp1.str() != "")
dump->push_back(iteminfo("TECHNIQUE", temp1.str()));
}
if ( showtext && !is_null() ) {
//dump << "\n\n" << type->description << "\n";
dump->push_back(iteminfo("DESCRIPTION", type->description));
if (contents.size() > 0) {
if (is_gun()) {
for (int i = 0; i < contents.size(); i++)
dump->push_back(iteminfo("DESCRIPTION", contents[i].type->description));
//dump << "\n " << contents[i].type->description;
} else
dump->push_back(iteminfo("DESCRIPTION", contents[0].type->description));
//dump << "\n " << contents[0].type->description;
//dump << "\n";
}
}
temp1.str("");
std::vector<iteminfo>& vecData = *dump; // vector is not copied here
for (int i = 0; i < vecData.size(); i++) {
if (vecData[i].sType == "DESCRIPTION")
temp1 << "\n";
temp1 << vecData[i].sName;
temp1 << vecData[i].sPre;
if (vecData[i].iValue != -999)
temp1 << vecData[i].iValue;
temp1 << vecData[i].sPost;
temp1 << ((vecData[i].bNewLine) ? "\n" : "");
}
return temp1.str();
}
char item::symbol()
{
if( is_null() )
return ' ';
return type->sym;
}
nc_color item::color(player *u)
{
nc_color ret = c_ltgray;
if (active) // Active items show up as yellow
ret = c_yellow;
else if (is_gun()) { // Guns are green if you are carrying ammo for them
ammotype amtype = ammo_type();
if (u->has_ammo(amtype).size() > 0)
ret = c_green;
} else if (is_ammo()) { // Likewise, ammo is green if you have guns that use it
ammotype amtype = ammo_type();
if (u->weapon.is_gun() && u->weapon.ammo_type() == amtype)
ret = c_green;
else {
for (int i = 0; i < u->inv.size(); i++) {
if (u->inv[i].is_gun() && u->inv[i].ammo_type() == amtype) {
i = u->inv.size();
ret = c_green;
}
}
}
} else if (is_book()) {
it_book* tmp = dynamic_cast<it_book*>(type);
if (tmp->type && tmp->intel <= u->int_cur + u->skillLevel(tmp->type) &&
(tmp->intel == 0 || !u->has_trait(PF_ILLITERATE)) &&
(u->skillLevel(tmp->type) >= tmp->req) &&
(u->skillLevel(tmp->type) < tmp->level))
ret = c_ltblue;
}
return ret;
}
nc_color item::color_in_inventory(player *u)
{
// Items in our inventory get colorized specially
nc_color ret = c_white;
if (active)
ret = c_yellow;
return ret;
}
std::string item::tname(game *g)
{
std::stringstream ret;
if (damage != 0 && !is_null()) {
std::string damtext;
switch (type->m1) {
case VEGGY:
case FLESH:
damtext = "partially eaten ";
break;
case COTTON:
case WOOL:
if (damage == -1) damtext = "reinforced ";
if (damage == 1) damtext = "ripped ";
if (damage == 2) damtext = "torn ";
if (damage == 3) damtext = "shredded ";
if (damage == 4) damtext = "tattered ";
break;
case LEATHER:
if (damage == -1) damtext = "reinforced ";
if (damage == 1) damtext = "scratched ";
if (damage == 2) damtext = "cut ";
if (damage == 3) damtext = "torn ";
if (damage == 4) damtext = "tattered ";
break;
case KEVLAR:
if (damage == -1) damtext = "reinforced ";
if (damage == 1) damtext = "marked ";
if (damage == 2) damtext = "dented ";
if (damage == 3) damtext = "scarred ";
if (damage == 4) damtext = "broken ";
break;
case PAPER:
if (damage == 1) damtext = "torn ";
if (damage >= 2) damtext = "shredded ";
break;
case WOOD:
if (damage == 1) damtext = "scratched ";
if (damage == 2) damtext = "chipped ";
if (damage == 3) damtext = "cracked ";
if (damage == 4) damtext = "splintered ";
break;
case PLASTIC:
case GLASS:
if (damage == 1) damtext = "scratched ";
if (damage == 2) damtext = "cut ";
if (damage == 3) damtext = "cracked ";
if (damage == 4) damtext = "shattered ";
break;
case IRON:
if (damage == 1) damtext = "lightly rusted ";
if (damage == 2) damtext = "rusted ";
if (damage == 3) damtext = "very rusty ";
if (damage == 4) damtext = "thoroughly rusted ";
break;
default:
//damtext = "damaged ";
if (damage == 1) damtext = "lightly damaged ";
if (damage == 2) damtext = "damaged ";
if (damage == 3) damtext = "very damaged ";
if (damage == 4) damtext = "thoroughly damaged ";
}
ret << damtext;
}
if (is_var_veh_part()){
//if(is_engine()){
if(type->bigness_aspect == BIGNESS_ENGINE_DISPLACEMENT){ //liters, e.g. "3.21-Liter V8 engine"
ret.precision(4);
ret << (float)bigness/100 << "-Liter ";
}
else if(type->bigness_aspect == BIGNESS_WHEEL_DIAMETER) { //inches, e.g. "20" wheel"
ret << bigness << "\" ";
}
}
if (volume() >= 4 && burnt >= volume() * 2)
ret << "badly burnt ";
else if (burnt > 0)
ret << "burnt ";
if (typeId() == itm_corpse) {
ret << corpse->name << " corpse";
if (name != "")
ret << " of " << name;
return ret.str();
} else if (typeId() == itm_blood) {
if (corpse == NULL || corpse->id == mon_null)
ret << "human blood";
else
ret << corpse->name << " blood";
return ret.str();
}
if (is_gun() && contents.size() > 0 ) {
ret << type->name;
for (int i = 0; i < contents.size(); i++)
ret << "+";
} else if (contents.size() == 1)
ret << type->name << " of " << contents[0].tname();
else if (contents.size() > 0)
ret << type->name << ", full";
else
ret << type->name;
it_comest* food = NULL;
if (is_food())
food = dynamic_cast<it_comest*>(type);
else if (is_food_container())
food = dynamic_cast<it_comest*>(contents[0].type);
if (food != NULL && g != NULL && food->spoils != 0 &&
int(g->turn) < (int)bday + 100)
ret << " (fresh)";
if (food != NULL && g != NULL && food->spoils != 0 &&
int(g->turn) - (int)bday > food->spoils * 600)
ret << " (rotten)";
if (owned > 0)
ret << " (owned)";
return ret.str();
}
nc_color item::color()
{
if (typeId() == itm_corpse)
return corpse->color;
if( is_null() )
return c_black;
return type->color;
}
int item::price()
{
if( is_null() )
return 0;
int ret = type->price;
for (int i = 0; i < contents.size(); i++)
ret += contents[i].price();
return ret;
}
int item::weight()
{
if (typeId() == itm_corpse) {
int ret;
switch (corpse->size) {
case MS_TINY: ret = 5; break;
case MS_SMALL: ret = 60; break;
case MS_MEDIUM: ret = 520; break;
case MS_LARGE: ret = 2000; break;
case MS_HUGE: ret = 4000; break;
}
if (made_of(VEGGY))
ret /= 10;
else if (made_of(IRON) || made_of(STEEL) || made_of(STONE))
ret *= 5;
return ret;
}
if( is_null() )
return 0;
int ret = type->weight;
if (count_by_charges() && !made_of(LIQUID)) {
ret *= charges;
ret /= 100;
}
for (int i = 0; i < contents.size(); i++)
if (contents[i].made_of(LIQUID))
{
if (contents[i].type->is_food())
{
it_comest* tmp_comest = dynamic_cast<it_comest*>(contents[i].type);
ret += contents[i].weight() * (contents[i].charges / tmp_comest->charges);
}
else if (contents[i].type->is_ammo())
{
it_ammo* tmp_ammo = dynamic_cast<it_ammo*>(contents[i].type);
ret += contents[i].weight() * (contents[i].charges / tmp_ammo->count);
}
else
ret += contents[i].weight();
}
else
ret += contents[i].weight();
return ret;
}
int item::volume()
{
if (typeId() == itm_corpse) {
switch (corpse->size) {
case MS_TINY: return 2;
case MS_SMALL: return 40;
case MS_MEDIUM: return 75;
case MS_LARGE: return 160;
case MS_HUGE: return 600;
}
}
if( is_null() )
return 0;
int ret = type->volume;
if (count_by_charges()) {
ret *= charges;
ret /= 100;
}
if (is_gun()) {
for (int i = 0; i < contents.size(); i++)
ret += contents[i].volume();
}
return ret;
}
int item::volume_contained()
{
int ret = 0;
for (int i = 0; i < contents.size(); i++)
ret += contents[i].volume();
return ret;
}
int item::attack_time()
{
int ret = 65 + 4 * volume() + 2 * weight();
return ret;
}
int item::damage_bash()
{
if( is_null() )
return 0;
return type->melee_dam;
}
int item::damage_cut()
{
if (is_gun()) {
for (int i = 0; i < contents.size(); i++) {
if (contents[i].typeId() == itm_bayonet)
return contents[i].type->melee_cut;
}
}
if( is_null() )
return 0;
return type->melee_cut;
}
bool item::has_flag(item_flag f)
{
if (is_gun()) {
if (mode == IF_MODE_AUX) {
item* gunmod = active_gunmod();
if( gunmod != NULL )
return gunmod->has_flag(f);
} else {
for (int i = 0; i < contents.size(); i++) {
// Don't report flags from active gunmods for the gun.
if (contents[i].has_flag(f) && contents[i].has_flag(IF_MODE_AUX))
return true;
}
}
}
if( is_null() )
return false;
return (type->item_flags & mfb(f));
}
bool item::has_technique(technique_id tech, player *p)
{
if (is_style()) {
it_style *style = dynamic_cast<it_style*>(type);
for (int i = 0; i < style->moves.size(); i++) {
if (style->moves[i].tech == tech &&
(!p || p->skillLevel("unarmed") >= style->moves[i].level))
return true;
}
}
if( is_null() )
return false;
return (type->techniques & mfb(tech));
}
int item::has_gunmod(int type)
{
if (!is_gun())
return -1;
for (int i = 0; i < contents.size(); i++)
if (contents[i].is_gunmod() && contents[i].typeId() == type)
return i;
return -1;
}
std::vector<technique_id> item::techniques()
{
std::vector<technique_id> ret;
for (int i = 0; i < NUM_TECHNIQUES; i++) {
if (has_technique( technique_id(i) ))
ret.push_back( technique_id(i) );
}
return ret;
}
bool item::rotten(game *g)