1 /*
2  * Copyright (C) 2011-2020 by the Widelands Development Team
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17  *
18  */
19 
20 #include "logic/map_objects/findbob.h"
21 
22 #include "base/macros.h"
23 #include "logic/map_objects/tribes/soldier.h"
24 #include "logic/player.h"
25 
26 namespace Widelands {
27 
accept(Bob * const bob) const28 bool FindBobAttribute::accept(Bob* const bob) const {
29 	return bob->has_attribute(attrib);
30 }
31 
accept(Bob * const imm) const32 bool FindBobEnemySoldier::accept(Bob* const imm) const {
33 	if (upcast(Soldier, soldier, imm))
34 		if (soldier->is_on_battlefield() && (!player || soldier->owner().is_hostile(*player)) &&
35 		    soldier->get_current_health())
36 			return true;
37 
38 	return false;
39 }
40 
accept(Bob * bob) const41 bool FindBobShip::accept(Bob* bob) const {
42 	return bob->descr().type() == MapObjectType::SHIP;
43 }
44 
accept(Bob * bob) const45 bool FindBobCritter::accept(Bob* bob) const {
46 	return bob->descr().type() == MapObjectType::CRITTER;
47 }
48 
49 }  // namespace Widelands
50