1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
|
/*
* Copyright (C) 2008-2013 by the Widelands Development Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef WL_LOGIC_FINDIMMOVABLE_H
#define WL_LOGIC_FINDIMMOVABLE_H
#include <stdint.h>
#include "logic/map_objects/map_object.h"
namespace Widelands {
struct BaseImmovable;
class ImmovableDescr;
class Player;
struct FindImmovable {
private:
struct BaseCapsule {
BaseCapsule() : refcount(1) {
}
virtual ~BaseCapsule() {
}
void addref() {
++refcount;
}
void deref() {
if (--refcount == 0)
delete this;
}
virtual bool accept(const BaseImmovable&) const = 0;
int refcount;
};
template <typename T> struct Capsule : public BaseCapsule {
Capsule(const T& init_op) : op(init_op) {
}
bool accept(const BaseImmovable& imm) const override {
return op.accept(imm);
}
const T op;
};
BaseCapsule* capsule;
public:
FindImmovable(const FindImmovable& o) {
capsule = o.capsule;
capsule->addref();
}
~FindImmovable() {
capsule->deref();
capsule = nullptr;
}
FindImmovable& operator=(const FindImmovable& o) {
capsule->deref();
capsule = o.capsule;
capsule->addref();
return *this;
}
template <typename T> FindImmovable(const T& op) {
capsule = new Capsule<T>(op);
}
// Return true if this node should be returned by find_fields()
bool accept(const BaseImmovable& imm) const {
return capsule->accept(imm);
}
};
const FindImmovable& find_immovable_always_true();
// FindImmovable functor
struct FindImmovableSize {
FindImmovableSize(int32_t const init_min, int32_t const init_max)
: min(init_min), max(init_max) {
}
bool accept(const BaseImmovable&) const;
private:
int32_t min, max;
};
struct FindImmovableType {
FindImmovableType(MapObjectType const init_type) : type(init_type) {
}
bool accept(const BaseImmovable&) const;
private:
MapObjectType type;
};
struct FindImmovableAttribute {
FindImmovableAttribute(uint32_t const init_attrib) : attrib(init_attrib) {
}
bool accept(const BaseImmovable&) const;
private:
int32_t attrib;
};
struct FindImmovablePlayerImmovable {
FindImmovablePlayerImmovable() {
}
bool accept(const BaseImmovable&) const;
};
struct FindImmovablePlayerMilitarySite {
FindImmovablePlayerMilitarySite(const Player& init_player) : player(init_player) {
}
bool accept(const BaseImmovable&) const;
const Player& player;
};
struct FindImmovableAttackable {
FindImmovableAttackable() {
}
bool accept(const BaseImmovable&) const;
};
struct FindImmovableByDescr {
FindImmovableByDescr(const ImmovableDescr& init_descr) : descr(init_descr) {
}
bool accept(const BaseImmovable&) const;
const ImmovableDescr& descr;
};
struct FindFlagOf {
FindFlagOf(const FindImmovable& init_finder) : finder(init_finder) {
}
bool accept(const BaseImmovable&) const;
const FindImmovable finder;
};
} // namespace Widelands
#endif // end of include guard: WL_LOGIC_FINDIMMOVABLE_H
|