From 50267ac4ad6c6ba02de89190b98b4888aafedb06 Mon Sep 17 00:00:00 2001 From: ketmar Date: Mon, 28 May 2012 07:20:10 +0300 Subject: [PATCH] better Burn command (don't show selection list if we have only one burning item) --- src/game/char.cpp | 53 ++++++++++++++++++++++++++++++++++++++++++++++ src/game/char.h | 2 ++ src/game/commands/Burn.cpp | 8 ++++++- 3 files changed, 62 insertions(+), 1 deletion(-) diff --git a/src/game/char.cpp b/src/game/char.cpp index 3d58aaf..8351b71 100644 --- a/src/game/char.cpp +++ b/src/game/char.cpp @@ -7610,6 +7610,59 @@ truth character::PossessesItem (sorter Sorter) const { } +truth character::MoreThanOnePossessesItem (sorter Sorter) const { + if (Sorter) { + int count = 0; + // + for (int c = 0; c < BodyParts; ++c) { + bodypart *BodyPart = GetBodyPart(c); + // + if (BodyPart && (Sorter == 0 || (BodyPart->*Sorter)(this))) { + if (++count > 1) return true; + } + } + for (int c = 0; c < GetEquipments(); ++c) { + item *Equipment = GetEquipment(c); + // + if (Equipment && (Sorter == 0 || (Equipment->*Sorter)(this))) { + if (++count > 1) return true; + } + } + for (int c = 0; c < GetStack()->GetItems(); ++c) { + item *Stk = GetStack()->GetItem(c); + // + if (Stk && (Sorter == 0 || (Stk->*Sorter)(this))) { + if (++count > 1) return true; + } + } + return false; + } + return false; +} + + +item *character::FirstPossessesItem (sorter Sorter) const { + if (Sorter) { + for (int c = 0; c < BodyParts; ++c) { + bodypart *BodyPart = GetBodyPart(c); + // + if (BodyPart && (Sorter == 0 || (BodyPart->*Sorter)(this))) return BodyPart; + } + for (int c = 0; c < GetEquipments(); ++c) { + item *Equipment = GetEquipment(c); + // + if (Equipment && (Sorter == 0 || (Equipment->*Sorter)(this))) return Equipment; + } + for (int c = 0; c < GetStack()->GetItems(); ++c) { + item *Stk = GetStack()->GetItem(c); + // + if (Stk && (Sorter == 0 || (Stk->*Sorter)(this))) return Stk; + } + } + return 0; +} + + /* 0 <= I <= 1 */ cchar *character::GetRunDescriptionLine (int I) const { if (!GetRunDescriptionLineOne().IsEmpty()) return !I ? GetRunDescriptionLineOne().CStr() : GetRunDescriptionLineTwo().CStr(); diff --git a/src/game/char.h b/src/game/char.h index d4411a6..248d73d 100644 --- a/src/game/char.h +++ b/src/game/char.h @@ -1102,6 +1102,8 @@ public: virtual truth IsPlayerKind () const { return false; } truth HasBodyPart (sorter) const; truth PossessesItem (sorter) const; + truth MoreThanOnePossessesItem (sorter) const; + item *FirstPossessesItem (sorter Sorter) const; truth IsFlying () const { return GetMoveType() & FLY; } virtual cchar *GetRunDescriptionLine (int) const; void VomitAtRandomDirection (int); diff --git a/src/game/commands/Burn.cpp b/src/game/commands/Burn.cpp index 7767660..b0fe71c 100644 --- a/src/game/commands/Burn.cpp +++ b/src/game/commands/Burn.cpp @@ -1,9 +1,15 @@ COMMAND(Burn) { + item *Item = 0; + // if (!Char->PossessesItem(&item::IsFlaming)) { ADD_MESSAGE("You have no flaming items, %s.", game::Insult()); return false; } - item *Item = Char->SelectFromPossessions(CONST_S("What do you want to use?"), &item::IsFlaming); + if (Char->MoreThanOnePossessesItem(&item::IsFlaming)) { + Item = Char->SelectFromPossessions(CONST_S("What do you want to use?"), &item::IsFlaming); + } else { + Item = Char->FirstPossessesItem(&item::IsFlaming); + } if (Item) { int Answer = game::DirectionQuestion(CONST_S("In what direction do you wish to burn? [press a direction key]"), false); if (Answer == DIR_ERROR) return false; -- 2.11.4.GIT