commands separated
[k8-i-v-a-n.git] / src / game / commands / Open.cpp
blob0ad57ccfd051d45c90dabddb2a863b196b5a4a21
1 COMMAND(Open) {
2 if (Char->CanOpen()) {
3 int Key;
4 truth OpenableItems = Char->GetStack()->SortedItems(Char, &item::IsOpenable);
5 //
6 if (OpenableItems) {
7 Key = game::AskForKeyPress(CONST_S("What do you wish to open? [press a direction key, space or i]"));
8 } else {
9 Key = game::AskForKeyPress(CONST_S("What do you wish to open? [press a direction key or space]"));
12 if (OpenableItems && (Key == 'i' || Key == 'I')) {
13 item *Item = Char->GetStack()->DrawContents(Char, CONST_S("What do you want to open?"), 0, &item::IsOpenable);
14 return Item && Item->Open(Char);
16 v2 DirVect = game::GetDirectionVectorForKey(Key);
17 if (DirVect != ERROR_V2 && Char->GetArea()->IsValidPos(Char->GetPos()+DirVect)) return Char->GetNearLSquare(Char->GetPos()+DirVect)->Open(Char);
18 } else {
19 ADD_MESSAGE("This monster type cannot open anything.");
21 return false;