1 /*
2  * Copyright (C) 2006-2019 Christopho, Solarus - http://www.solarus-games.org
3  *
4  * Solarus is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * Solarus 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 along
15  * with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 #include "solarus/core/Debug.h"
18 #include "solarus/entities/EntityTypeInfo.h"
19 
20 namespace Solarus {
21 
22 const std::string EnumInfoTraits<EntityType>::pretty_name = "entity type";
23 
24 /**
25  * \brief Lua name of each map entity type.
26  */
27 const EnumInfo<EntityType>::names_type EnumInfoTraits<EntityType>::names = {
28     { EntityType::ARROW, "arrow" },
29     { EntityType::BLOCK, "block" },
30     { EntityType::BOMB, "bomb" },
31     { EntityType::BOOMERANG, "boomerang" },
32     { EntityType::CAMERA, "camera" },
33     { EntityType::CARRIED_OBJECT, "carried_object" },
34     { EntityType::CHEST, "chest" },
35     { EntityType::CRYSTAL, "crystal" },
36     { EntityType::CRYSTAL_BLOCK, "crystal_block" },
37     { EntityType::CUSTOM, "custom_entity" },
38     { EntityType::DESTINATION, "destination" },
39     { EntityType::DESTRUCTIBLE, "destructible" },
40     { EntityType::DOOR, "door" },
41     { EntityType::DYNAMIC_TILE, "dynamic_tile" },
42     { EntityType::ENEMY, "enemy" },
43     { EntityType::EXPLOSION, "explosion" },
44     { EntityType::HERO, "hero" },
45     { EntityType::HOOKSHOT, "hookshot" },
46     { EntityType::FIRE, "fire" },
47     { EntityType::JUMPER, "jumper" },
48     { EntityType::NPC, "npc" },
49     { EntityType::PICKABLE, "pickable" },
50     { EntityType::SENSOR, "sensor" },
51     { EntityType::SEPARATOR, "separator" },
52     { EntityType::SHOP_TREASURE, "shop_treasure" },
53     { EntityType::STAIRS, "stairs" },
54     { EntityType::STREAM, "stream" },
55     { EntityType::SWITCH, "switch" },
56     { EntityType::TELETRANSPORTER, "teletransporter" },
57     { EntityType::TILE, "tile" },
58     { EntityType::WALL, "wall" }
59 };
60 
61 /**
62  * \brief Returns whether entities of the specified type can be stored in map files.
63  * \param type A type of entity.
64  * \return \c true if this type can be stored.
65  */
can_be_stored_in_map_file(EntityType type)66 bool EntityTypeInfo::can_be_stored_in_map_file(EntityType type) {
67 
68   switch (type) {
69 
70   case EntityType::BLOCK:
71   case EntityType::CHEST:
72   case EntityType::CRYSTAL:
73   case EntityType::CRYSTAL_BLOCK:
74   case EntityType::CUSTOM:
75   case EntityType::DESTINATION:
76   case EntityType::DESTRUCTIBLE:
77   case EntityType::DOOR:
78   case EntityType::DYNAMIC_TILE:
79   case EntityType::ENEMY:
80   case EntityType::JUMPER:
81   case EntityType::NPC:
82   case EntityType::PICKABLE:
83   case EntityType::SENSOR:
84   case EntityType::SEPARATOR:
85   case EntityType::SHOP_TREASURE:
86   case EntityType::STAIRS:
87   case EntityType::STREAM:
88   case EntityType::SWITCH:
89   case EntityType::TELETRANSPORTER:
90   case EntityType::TILE:
91   case EntityType::WALL:
92     return true;
93 
94   case EntityType::ARROW:
95   case EntityType::BOMB:
96   case EntityType::BOOMERANG:
97   case EntityType::CAMERA:
98   case EntityType::CARRIED_OBJECT:
99   case EntityType::EXPLOSION:
100   case EntityType::HERO:
101   case EntityType::HOOKSHOT:
102   case EntityType::FIRE:
103     return false;
104   }
105 
106   return false;
107 }
108 
109 /**
110  * \brief Returns whether entities of the specified type can be created
111  * dynamically by using the Lua scripting API.
112  * \param type A type of entity.
113  * \return \c true if this type can be created through the scripting API.
114  */
can_be_created_from_lua_api(EntityType type)115 bool EntityTypeInfo::can_be_created_from_lua_api(EntityType type) {
116 
117   switch (type) {
118 
119   case EntityType::BLOCK:
120   case EntityType::BOMB:
121   case EntityType::CHEST:
122   case EntityType::CRYSTAL:
123   case EntityType::CRYSTAL_BLOCK:
124   case EntityType::CUSTOM:
125   case EntityType::DESTINATION:
126   case EntityType::DESTRUCTIBLE:
127   case EntityType::DOOR:
128   case EntityType::DYNAMIC_TILE:
129   case EntityType::ENEMY:
130   case EntityType::EXPLOSION:
131   case EntityType::FIRE:
132   case EntityType::JUMPER:
133   case EntityType::NPC:
134   case EntityType::PICKABLE:
135   case EntityType::SENSOR:
136   case EntityType::SEPARATOR:
137   case EntityType::SHOP_TREASURE:
138   case EntityType::STAIRS:
139   case EntityType::STREAM:
140   case EntityType::SWITCH:
141   case EntityType::TELETRANSPORTER:
142   case EntityType::WALL:
143     // These ones can be created by scripts.
144     return true;
145 
146   case EntityType::ARROW:
147   case EntityType::BOOMERANG:
148   case EntityType::CAMERA:
149   case EntityType::CARRIED_OBJECT:
150   case EntityType::HERO:
151   case EntityType::HOOKSHOT:
152   case EntityType::TILE:
153     // These ones are only created by the engine.
154     // Tiles can only stored in the map data file.
155     return false;
156 
157   }
158 
159   return false;
160 }
161 
162 }  // namespace Solarus
163 
164