cosmetix
[k8-i-v-a-n.git] / src / game / items / materialcontainer_backpack.cpp
blob7699fc53800c2bf377aa50754a96900cc48cfc56
1 #ifdef HEADER_PHASE
2 ITEM(backpack, materialcontainer)
4 public:
5 virtual truth Apply(character*);
6 virtual truth IsAppliable(ccharacter*) const { return true; }
7 virtual truth ReceiveDamage(character*, int, int, int);
8 virtual truth IsExplosive() const;
9 virtual sLong GetTotalExplosivePower() const;
10 virtual void SpillFluid(character*, liquid*, int = 0);
11 protected:
12 virtual void AddPostFix(festring& String, int) const { AddContainerPostFix(String); }
16 #else
20 truth backpack::IsExplosive() const { return GetSecondaryMaterial() && GetSecondaryMaterial()->IsExplosive(); }
24 sLong backpack::GetTotalExplosivePower() const { return GetSecondaryMaterial() ? GetSecondaryMaterial()->GetTotalExplosivePower() : 0; }
28 truth backpack::Apply(character* Terrorist)
30 if(IsExplosive())
32 if(Terrorist->IsPlayer())
33 ADD_MESSAGE("You light your %s. It explodes!", CHAR_NAME(UNARTICLED));
34 else if(Terrorist->CanBeSeenByPlayer())
35 ADD_MESSAGE("%s lights %s. It explodes!", Terrorist->CHAR_NAME(DEFINITE), CHAR_NAME(INDEFINITE));
36 else if(GetSquareUnder()->CanBeSeenByPlayer(true))
37 ADD_MESSAGE("Something explodes!");
39 RemoveFromSlot();
40 SendToHell();
41 Terrorist->DexterityAction(5);
42 Terrorist->GetLevel()->Explosion(Terrorist, CONST_S("kamikazed @k"), Terrorist->GetLSquareUnder()->GetPos(), GetSecondaryMaterial()->GetTotalExplosivePower());
43 return true;
45 else if(Terrorist->IsPlayer())
46 ADD_MESSAGE("You are not able to explode yourself with this crummy %s!", CHAR_NAME(UNARTICLED));
48 return false;
53 truth backpack::ReceiveDamage(character* Damager, int Damage, int Type, int)
55 if(Type & (FIRE|ENERGY) && Damage && IsExplosive() && (Damage > 25 || !(RAND() % (50 / Damage))))
57 festring DeathMsg = CONST_S("killed by an explosion of ");
58 AddName(DeathMsg, INDEFINITE);
60 if(Damager)
61 DeathMsg << " caused @bk";
63 if(GetSquareUnder()->CanBeSeenByPlayer(true))
64 ADD_MESSAGE("%s explodes!", GetExtendedDescription().CStr());
66 lsquare* Square = GetLSquareUnder();
67 RemoveFromSlot();
68 SendToHell();
69 Square->GetLevel()->Explosion(Damager, DeathMsg, Square->GetPos(), GetSecondaryMaterial()->GetTotalExplosivePower());
70 return true;
73 return false;
78 void backpack::SpillFluid(character* Spiller, liquid* Liquid, int SquareIndex)
80 if(!Liquid->IsExplosive())
82 GetSecondaryMaterial()->AddWetness(Liquid->GetVolume() * 25);
84 if(CanBeSeenByPlayer())
85 ADD_MESSAGE("%s gets wet.", CHAR_NAME(DEFINITE));
88 item::SpillFluid(Spiller, Liquid, SquareIndex);
90 #endif