1 /** 2 ** continf.h - Container rule information from 'shape_info.txt'. 3 ** 4 ** Written: 06/01/2008 - Marzo 5 **/ 6 7 #ifndef INCL_CONTINF_H 8 #define INCL_CONTINF_H 1 9 10 /* 11 Copyright (C) 2008 The Exult Team 12 13 This program is free software; you can redistribute it and/or 14 modify it under the terms of the GNU General Public License 15 as published by the Free Software Foundation; either version 2 16 of the License, or (at your option) any later version. 17 18 This program is distributed in the hope that it will be useful, 19 but WITHOUT ANY WARRANTY; without even the implied warranty of 20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 GNU General Public License for more details. 22 23 You should have received a copy of the GNU General Public License 24 along with this program; if not, write to the Free Software 25 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 26 */ 27 28 #include "baseinf.h" 29 #include "exult_constants.h" 30 31 #include <iosfwd> 32 33 class Shape_info; 34 35 /* 36 * Information about shapes accepted/rejected by containers. 37 * This is meant to be stored in a totally ordered vector. 38 */ 39 class Content_rules : public Base_info { 40 int shape; 41 bool accept; 42 public: 43 friend class Shape_info; 44 Content_rules() = default; 45 Content_rules(int sh, bool a, bool p = false, bool m = false, 46 bool st = false, bool inv = false) { 47 set(sh, a, p, m, st, inv); 48 } Content_rules(const Content_rules & other)49 Content_rules(const Content_rules &other) 50 : Base_info(other), shape(other.shape), accept(other.accept) { 51 info_flags = other.info_flags; 52 } 53 // Read in from file. 54 bool read(std::istream &in, int version, Exult_Game game); 55 // Write out. 56 void write(std::ostream &out, int shapenum, Exult_Game game); 57 void set(int sh, bool a, bool p = false, bool m = false, 58 bool st = false, bool inv = false) { 59 shape = sh; 60 accept = a; 61 set_patch(p); 62 set_modified(m); 63 set_static(st); 64 set_invalid(inv); 65 } invalidate()66 void invalidate() { 67 accept = true; 68 set_invalid(true); 69 } get_shape()70 int get_shape() const { 71 return shape; 72 } accepts_shape()73 bool accepts_shape() const { 74 return accept; 75 } set_accept(bool tf)76 void set_accept(bool tf) { 77 if (accept != tf) { 78 set_modified(true); 79 accept = tf; 80 } 81 } 82 bool operator<(const Content_rules &other) const { 83 auto shp1 = static_cast<unsigned short>(shape); 84 auto shp2 = static_cast<unsigned short>(other.shape); 85 return shp1 < shp2; 86 } 87 bool operator==(const Content_rules &other) const { 88 return this == &other || (!(*this < other) && !(other < *this)); 89 } 90 bool operator!=(const Content_rules &other) const { 91 return !(*this == other); 92 } 93 Content_rules &operator=(const Content_rules &other) { 94 if (this != &other) { 95 shape = other.shape; 96 accept = other.accept; 97 info_flags = other.info_flags; 98 } 99 return *this; 100 } set(const Content_rules & other)101 void set(const Content_rules &other) { 102 // Assumes *this == other. 103 // No need to guard against self-assignment. 104 // Do NOT copy modified or static flags. 105 set_patch(other.from_patch()); 106 set_invalid(other.is_invalid()); 107 set_accept(other.accept); 108 } 109 enum { is_binary = 0, entry_size = 0 }; 110 }; 111 112 #endif 113