item classes moved to separate files
[k8-i-v-a-n.git] / src / game / items / scroll_scrollofgolemcreation.cpp
blob736bb3a6c3543f616ee71b2109dd8a46c8e2be8a
1 #ifdef HEADER_PHASE
2 ITEM(scrollofgolemcreation, scroll)
4 public:
5 virtual void FinishReading(character*);
6 };
9 #else
13 void scrollofgolemcreation::FinishReading(character* Reader)
15 for(;;)
17 itemvector Item;
19 if(!Reader->SelectFromPossessions(Item, CONST_S("Which item do you wish to use for golem creation?"), NO_MULTI_SELECT, &item::IsDestroyable))
21 ADD_MESSAGE("You notice you haven't got anything to change into a golem.");
22 return;
25 if(!Item.empty())
27 material* Main = Item[0]->GetMainMaterial();
28 material* Sec = Item[0]->GetSecondaryMaterial();
29 truth MainPossible = Main->GetCategoryFlags() & IS_GOLEM_MATERIAL;
30 truth SecPossible = Sec && Sec->GetVolume()
31 && Sec->GetCategoryFlags() & IS_GOLEM_MATERIAL
32 && !Sec->IsSameAs(Main);
34 if(!MainPossible && !SecPossible)
36 ADD_MESSAGE("You can't use that for golem creation.");
37 continue;
40 if (MainPossible && SecPossible) {
41 if (game::TruthQuestion(CONST_S("Use main material? [Y/n]"), YES)) SecPossible = false; else MainPossible = false;
44 int MaterialConfig = MainPossible ? Main->GetConfig() : Sec->GetConfig();
45 golem* Golem = golem::Spawn(MaterialConfig);
46 sLong Volume = MainPossible ? Sec && Sec->IsSameAs(Main)
47 ? Main->GetVolume() + Sec->GetVolume()
48 : Main->GetVolume() : Sec->GetVolume();
49 Golem->SetItemVolume(Volume);
50 v2 Where = GetLevel()->GetNearestFreeSquare(Golem, Reader->GetPos());
51 Item[0]->RemoveFromSlot();
52 Item[0]->SendToHell();
54 if(Where == ERROR_V2)
56 ADD_MESSAGE("You cast the spell and %s is sucked into a rainbow-coled magical vortex, but nothing happens.", Item[0]->CHAR_NAME(DEFINITE));
57 delete Golem;
59 else
61 ADD_MESSAGE("You cast the spell and %s is sucked into a rainbow-coled magical vortex.", Item[0]->CHAR_NAME(DEFINITE));
62 Golem->SetTeam(Reader->GetTeam());
63 Golem->PutTo(Where);
65 if(Golem->CanBeSeenByPlayer())
66 ADD_MESSAGE("Suddenly %s materializes!", Golem->CHAR_NAME(INDEFINITE));
68 Golem->GetLSquareUnder()->DrawParticles(RED);
71 break;
73 else if(game::TruthQuestion(CONST_S("Really cancel read? [y/N]")))
74 return;
77 RemoveFromSlot();
78 SendToHell();
79 Reader->EditExperience(INTELLIGENCE, 300, 1 << 12);
81 #endif