1 /* Copyright (C) 2013-2014 Michal Brzozowski (rusolis@poczta.fm)
2 
3    This file is part of KeeperRL.
4 
5    KeeperRL is free software; you can redistribute it and/or modify it under the terms of the
6    GNU General Public License as published by the Free Software Foundation; either version 2
7    of the License, or (at your option) any later version.
8 
9    KeeperRL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
10    even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11    GNU General Public License for more details.
12 
13    You should have received a copy of the GNU General Public License along with this program.
14    If not, see http://www.gnu.org/licenses/ . */
15 
16 #pragma once
17 
18 #include "util.h"
19 #include "unique_entity.h"
20 #include "entity_map.h"
21 
22 class Creature;
23 class Item;
24 
25 class MinionEquipment {
26   public:
27 
28   static bool isItemUseful(WConstItem);
29   bool needsItem(WConstCreature c, WConstItem it, bool noLimit = false) const;
30   optional<UniqueEntity<Creature>::Id> getOwner(WConstItem) const;
31   bool isOwner(WConstItem, WConstCreature) const;
32   bool tryToOwn(WConstCreature, WItem);
33   void discard(WConstItem);
34   void discard(UniqueEntity<Item>::Id);
35   void updateOwners(const vector<WCreature>&);
36   vector<WItem> getItemsOwnedBy(WConstCreature, ItemPredicate = nullptr) const;
37 
38   template <class Archive>
39   void serialize(Archive& ar, const unsigned int version);
40 
41   void setLocked(WConstCreature, UniqueEntity<Item>::Id, bool locked);
42   bool isLocked(WConstCreature, UniqueEntity<Item>::Id) const;
43   void sortByEquipmentValue(WConstCreature, vector<WItem>& items) const;
44   void autoAssign(WConstCreature, vector<WItem> possibleItems);
45   void updateItems(const vector<WItem>& items);
46 
47   private:
48   enum EquipmentType { ARMOR, HEALING, COMBAT_ITEM };
49 
50   static optional<EquipmentType> getEquipmentType(WConstItem it);
51   optional<int> getEquipmentLimit(EquipmentType type) const;
52   WItem getWorstItem(WConstCreature, vector<WItem>) const;
53   int getItemValue(WConstCreature, WConstItem) const;
54 
55   EntityMap<Item, UniqueEntity<Creature>::Id> SERIAL(owners);
56   EntityMap<Creature, vector<WItem>> SERIAL(myItems);
57   set<pair<UniqueEntity<Creature>::Id, UniqueEntity<Item>::Id>> SERIAL(locked);
58 };
59 
60