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 "debug.h" 19 #include "enums.h" 20 #include "util.h" 21 #include "unique_entity.h" 22 #include "view_layer.h" 23 #include "attr_type.h" 24 25 RICH_ENUM(ViewObjectModifier, PLAYER, HIDDEN, INVISIBLE, ILLUSION, PLANNED, 26 TEAM_LEADER_HIGHLIGHT, TEAM_HIGHLIGHT, DRAW_MORALE, ROAD, NO_UP_MOVEMENT, REMEMBER, SPIRIT_DAMAGE, HOSTILE); 27 RICH_ENUM(ViewObjectAttribute, WOUNDED, BURNING, WATER_DEPTH, EFFICIENCY, MORALE); 28 29 struct MovementInfo { 30 enum Type { MOVE, ATTACK }; 31 MovementInfo(Vec2 direction, double tBegin, double tEnd, Type); 32 MovementInfo(); 33 Vec2 direction; 34 double tBegin; 35 double tEnd; 36 Type type; 37 }; 38 39 class ViewObject { 40 public: 41 typedef ViewObjectModifier Modifier; 42 typedef ViewObjectAttribute Attribute; 43 ViewObject(ViewId id, ViewLayer l, const string& description); 44 ViewObject(ViewId id, ViewLayer l); 45 46 ViewObject& setModifier(Modifier); 47 ViewObject& removeModifier(Modifier); 48 bool hasModifier(Modifier) const; 49 50 static void setHallu(bool); 51 52 ViewObject& setAttachmentDir(Dir); 53 optional<Dir> getAttachmentDir() const; 54 55 ViewObject& setAttribute(Attribute, double); 56 optional<float> getAttribute(Attribute) const; 57 58 using CreatureAttributes = EnumMap<AttrType, std::uint16_t>; 59 void setCreatureAttributes(CreatureAttributes); 60 const optional<CreatureAttributes>& getCreatureAttributes() const; 61 62 const char* getDescription() const; 63 64 ViewLayer layer() const; 65 ViewId id() const; 66 void setId(ViewId); 67 68 void setGoodAdjectives(const string&); 69 void setBadAdjectives(const string&); 70 const string& getGoodAdjectives() const; 71 const string& getBadAdjectives() const; 72 73 void setDescription(const string&); 74 75 void addMovementInfo(MovementInfo); 76 void clearMovementInfo(); 77 bool hasAnyMovementInfo() const; 78 MovementInfo getLastMovementInfo() const; 79 Vec2 getMovementInfo(double tBegin) const; 80 81 void setCreatureId(UniqueEntity<Creature>::Id); 82 optional<UniqueEntity<Creature>::Id> getCreatureId() const; 83 84 const static ViewObject& unknownMonster(); 85 const static ViewObject& empty(); 86 const static ViewObject& mana(); 87 88 SERIALIZATION_DECL(ViewObject); 89 90 private: 91 string getAttributeString(Attribute) const; 92 const char* getDefaultDescription() const; 93 EnumSet<Modifier> SERIAL(modifiers); 94 EnumMap<Attribute, optional<float>> SERIAL(attributes); 95 ViewId SERIAL(resource_id); 96 ViewLayer SERIAL(viewLayer); 97 optional<string> SERIAL(description); 98 optional<Dir> SERIAL(attachmentDir); 99 optional<UniqueEntity<Creature>::Id> SERIAL(creatureId); 100 string SERIAL(goodAdjectives); 101 string SERIAL(badAdjectives); 102 optional<CreatureAttributes> SERIAL(creatureAttributes); 103 104 class MovementQueue { 105 public: 106 void add(MovementInfo); 107 const MovementInfo& getLast() const; 108 Vec2 getTotalMovement(double tBegin) const; 109 bool hasAny() const; 110 void clear(); 111 112 private: 113 int makeGoodIndex(int index) const; 114 std::array<MovementInfo, 6> elems; 115 int index = 0; 116 int totalMoves = 0; 117 } movementQueue; 118 }; 119 120