cosmetix
[k8-i-v-a-n.git] / src / game / items / item_oillamp.cpp
blob11d38773603d0eb26ab56b2505dec4d9810c94f3
1 #ifdef HEADER_PHASE
2 ITEM(oillamp, item)
4 public:
5 oillamp();
6 oillamp(const oillamp&);
7 virtual void Save(outputfile&) const;
8 virtual void Load(inputfile&);
9 virtual truth GetInhabitedByGenie() const { return InhabitedByGenie; }
10 virtual void SetInhabitedByGenie(truth What) { InhabitedByGenie = What; }
11 virtual truth Apply(character*);
12 virtual truth IsAppliable(ccharacter*) const { return true; }
13 protected:
14 truth InhabitedByGenie;
18 #else
22 truth oillamp::Apply(character* Applier)
24 if(Applier->IsPlayer())
25 ADD_MESSAGE("You rub %s.", CHAR_NAME(DEFINITE));
27 if(GetInhabitedByGenie())
29 genie* Genie = genie::Spawn();
30 v2 TryToCreate;
31 truth FoundPlace = false;
33 if(RAND_N(5))
34 Genie->SetTeam(Applier->GetTeam());
35 else
36 Genie->SetTeam(game::GetTeam(MONSTER_TEAM));
38 /* First try to create a genie nearby (10 tries - if all of them fail then stop trying) */
40 for(int c = 0; c < 10 && !FoundPlace; ++c)
42 TryToCreate = Applier->GetPos() + game::GetMoveVector(RAND() % DIRECTION_COMMAND_KEYS);
44 if(GetArea()->IsValidPos(TryToCreate) && Genie->CanMoveOn(GetNearLSquare(TryToCreate)) && Genie->IsFreeForMe(GetNearLSquare(TryToCreate)))
46 Genie->PutTo(TryToCreate);
47 FoundPlace = true;
48 SetInhabitedByGenie(false);
49 break;
53 if(FoundPlace)
55 Genie->GetLSquareUnder()->AddSmoke(gas::Spawn(SMOKE, 1000));
57 if(!Genie->IsPet())
58 ADD_MESSAGE("You see a puff of smoke, and %s appears. \"For centuries I have been imprisoned in this lamp. But at last you have freed me! As a reward, I will kill you.\"", Genie->CHAR_NAME(INDEFINITE));
59 else
61 if(Applier->IsPlayer())
63 ADD_MESSAGE("You see a puff of smoke, and %s appears. \"For centuries I have been imprisoned in this lamp. But at last you have freed me! I am deeply grateful. You deserve a generous reward. I may serve you for 1001 nights or grant you a wish. It's your choice.\"", Genie->CHAR_NAME(INDEFINITE));
65 if(game::TruthQuestion(CONST_S("Do you want to wish? [Y/n]"), YES))
67 ADD_MESSAGE("You may wish for an item.");
68 game::Wish(Applier,
69 "%s appears from nothing and the genie flies happily away!",
70 "Two %s appear from nothing and the genie flies happily away!");
72 Genie->Remove();
73 delete Genie;
74 Applier->EditAP(-1000);
75 return true;
80 meleeweapon* Weapon = meleeweapon::Spawn(TWO_HANDED_SCIMITAR, NO_MATERIALS);
81 Weapon->InitMaterials(MAKE_MATERIAL(ARCANITE), MAKE_MATERIAL(ARCANITE), true);
82 Genie->SetRightWielded(Weapon);
83 ADD_MESSAGE("%s wishes for a two-handed scimitar. Suddenly %s appears from nothing and %s wields it.", Genie->CHAR_NAME(DEFINITE), Genie->GetMainWielded()->CHAR_NAME(INDEFINITE), Genie->CHAR_NAME(DEFINITE));
85 else
87 if(Applier->IsPlayer())
88 ADD_MESSAGE("You feel that it is warmer.");
90 delete Genie;
93 else
94 if(Applier->IsPlayer())
95 ADD_MESSAGE("Nothing happens.");
97 Applier->EditAP(-1000);
98 return true;
103 void oillamp::Save(outputfile& SaveFile) const
105 item::Save(SaveFile);
106 SaveFile << InhabitedByGenie;
111 void oillamp::Load(inputfile& SaveFile)
113 item::Load(SaveFile);
114 SaveFile >> InhabitedByGenie;
119 oillamp::oillamp()
121 if(!game::IsLoading())
122 InhabitedByGenie = RAND_2;
127 oillamp::oillamp(const oillamp& Lamp) : mybase(Lamp), InhabitedByGenie(false)
130 #endif