save and bone files now can be compressed with ZLib (wow!)
[k8-i-v-a-n.git] / src / game / traps.cpp
blob491e8d6dd59235b360c99d80222406585e3fdca7
1 /*
3 * Iter Vehemens ad Necem (IVAN)
4 * Copyright (C) Timo Kiviluoto
5 * Released under the GNU General
6 * Public License
8 * See LICENSING which should be included
9 * along with this file for more details
12 /* Compiled through trapset.cpp */
15 web::web () {
16 if (!game::IsLoading()) {
17 TrapData.TrapID = game::CreateNewTrapID(this);
18 TrapData.VictimID = 0;
19 Picture = new bitmap(TILE_V2, TRANSPARENT_COLOR);
20 bitmap Temp(TILE_V2, TRANSPARENT_COLOR);
21 Temp.ActivateFastFlag();
22 packcol16 Color = MakeRGB16(250, 250, 250);
23 const rawbitmap *Effect = igraph::GetRawGraphic(GR_EFFECT);
24 Effect->MaskedBlit(&Temp, v2(RAND_2 ? 64 : 80, 32), ZERO_V2, TILE_V2, &Color);
25 Temp.NormalBlit(Picture, Flags);
30 web::~web () {
31 game::RemoveTrapID(TrapData.TrapID);
35 truth web::TryToUnStick (character *Victim, v2) {
36 feuLong TrapID = GetTrapID();
37 int Modifier = 7*GetTrapBaseModifier()/Max(Victim->GetAttribute(DEXTERITY)+Victim->GetAttribute(ARM_STRENGTH), 1);
38 if (!RAND_N(Max(Modifier, 2))) {
39 Victim->RemoveTrap(TrapID);
40 TrapData.VictimID = 0;
41 if (Victim->IsPlayer()) ADD_MESSAGE("You manage to free yourself from the web.");
42 else if (Victim->CanBeSeenByPlayer()) ADD_MESSAGE("%s manages to free %sself from the web.", Victim->CHAR_NAME(DEFINITE), Victim->CHAR_OBJECT_PRONOUN);
43 Victim->EditAP(-500);
44 return true;
46 if (!RAND_N(Max(Modifier << 1, 2))) {
47 Victim->RemoveTrap(TrapID);
48 TrapData.VictimID = 0;
49 GetLSquareUnder()->RemoveTrap(this);
50 SendToHell();
51 if (Victim->IsPlayer()) ADD_MESSAGE("You tear the web down.");
52 else if (Victim->CanBeSeenByPlayer()) ADD_MESSAGE("%s tears the web down.", Victim->CHAR_NAME(DEFINITE));
53 Victim->EditAP(-500);
54 return true;
56 Modifier = GetTrapBaseModifier()*(Victim->GetAttribute(DEXTERITY)+Victim->GetAttribute(ARM_STRENGTH))/75;
57 if (Victim->CanChokeOnWeb(this) && !RAND_N(Max(Modifier << 3, 2))) {
58 if (Victim->IsPlayer()) ADD_MESSAGE("You manage to choke yourself on the web.");
59 else if (Victim->CanBeSeenByPlayer()) ADD_MESSAGE("%s chokes %sself on the web.", Victim->CHAR_NAME(DEFINITE), Victim->CHAR_OBJECT_PRONOUN);
60 Victim->LoseConsciousness(250 + RAND_N(250));
61 Victim->EditAP(-1000);
62 return true;
64 if (!RAND_N(Max(Modifier, 2))) {
65 int VictimBodyPart = Victim->GetRandomBodyPart(ALL_BODYPART_FLAGS&~TrapData.BodyParts);
66 if (VictimBodyPart != NONE_INDEX) {
67 TrapData.BodyParts |= 1 << VictimBodyPart;
68 Victim->AddTrap(GetTrapID(), 1 << VictimBodyPart);
69 if (Victim->IsPlayer())
70 ADD_MESSAGE("You fail to free yourself from the web and your %s is stuck in it in the attempt.", Victim->GetBodyPartName(VictimBodyPart).CStr());
71 else if (Victim->CanBeSeenByPlayer())
72 ADD_MESSAGE("%s tries to free %sself from the web but is stuck more tightly in it in the attempt.", Victim->CHAR_NAME(DEFINITE), Victim->CHAR_OBJECT_PRONOUN);
73 Victim->EditAP(-1000);
74 return true;
77 if (Victim->IsPlayer()) ADD_MESSAGE("You are unable to escape from the web.");
78 Victim->EditAP(-1000);
79 return false;
83 void web::Save (outputfile &SaveFile) const {
84 trap::Save(SaveFile);
85 SaveFile << TrapData << Strength << Picture;
89 void web::Load (inputfile &SaveFile) {
90 trap::Load(SaveFile);
91 SaveFile >> TrapData >> Strength >> Picture;
92 game::AddTrapID(this, TrapData.TrapID);
96 void web::StepOnEffect (character *Stepper) {
97 if (Stepper->IsImmuneToStickiness()) return;
98 int StepperBodyPart = Stepper->GetRandomBodyPart();
99 if (StepperBodyPart == NONE_INDEX) return;
100 TrapData.VictimID = Stepper->GetID();
101 TrapData.BodyParts = 1 << StepperBodyPart;
102 Stepper->AddTrap(GetTrapID(), 1 << StepperBodyPart);
103 if (Stepper->IsPlayer())
104 ADD_MESSAGE("You try to step through the web but your %s sticks in it.", Stepper->GetBodyPartName(StepperBodyPart).CStr());
105 else if (Stepper->CanBeSeenByPlayer())
106 ADD_MESSAGE("%s gets stuck in the web.", Stepper->CHAR_NAME(DEFINITE));
110 void web::AddDescription (festring &Msg) const {
111 Msg << ". A web envelops the square";
115 void web::AddTrapName (festring &String, int) const {
116 String << "a spider web";
120 void web::Draw (blitdata &BlitData) const {
121 Picture->LuminanceMaskedBlit(BlitData);
125 truth web::IsStuckToBodyPart (int I) const {
126 return 1 << I & TrapData.BodyParts;
130 void web::ReceiveDamage (character *, int, int Type, int) {
131 if (Type & (ACID|FIRE|ELECTRICITY|ENERGY)) Destroy();
135 void web::Destroy () {
136 Untrap();
137 GetLSquareUnder()->RemoveTrap(this);
138 SendToHell();
142 truth web::CanBeSeenBy (ccharacter *Who) const {
143 return (GetLSquareUnder()->CanBeSeenBy(Who) && Who->GetAttribute(WISDOM) > 4);
147 void web::PreProcessForBone () {
148 trap::PreProcessForBone();
149 game::RemoveTrapID(TrapData.TrapID);
150 TrapData.TrapID = 0;
154 void web::PostProcessForBone () {
155 trap::PostProcessForBone();
156 TrapData.TrapID = game::CreateNewTrapID(this);
160 void web::Untrap () {
161 character *Char = game::SearchCharacter(GetVictimID());
162 if (Char) Char->RemoveTrap(GetTrapID());
163 TrapData.VictimID = 0;