1 /* 2 * Copyright (C) 2006-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 #ifndef WL_SCRIPTING_LUA_GAME_H 21 #define WL_SCRIPTING_LUA_GAME_H 22 23 #include "logic/message_id.h" 24 #include "scripting/lua.h" 25 #include "scripting/lua_bases.h" 26 #include "scripting/luna.h" 27 28 namespace Widelands { 29 class TribeDescr; 30 class Objective; 31 struct Message; 32 } // namespace Widelands 33 34 namespace LuaGame { 35 36 /* 37 * Base class for all classes in wl.game 38 */ 39 class LuaGameModuleClass : public LunaClass { 40 public: get_modulename()41 const char* get_modulename() override { 42 return "game"; 43 } 44 }; 45 46 class LuaPlayer : public LuaBases::LuaPlayerBase { 47 public: 48 // Overwritten from LuaPlayerBase, avoid ambiguity when deriving from 49 // LuaGameModuleClass and LuaPlayerBase get_modulename()50 const char* get_modulename() override { 51 return "game"; 52 } 53 54 LUNA_CLASS_HEAD(LuaPlayer); 55 LuaPlayer()56 LuaPlayer() : LuaBases::LuaPlayerBase() { 57 } LuaPlayer(Widelands::PlayerNumber n)58 explicit LuaPlayer(Widelands::PlayerNumber n) : LuaBases::LuaPlayerBase(n) { 59 } LuaPlayer(lua_State * L)60 explicit LuaPlayer(lua_State* L) { 61 report_error(L, "Cannot instantiate a 'Player' directly!"); 62 } 63 64 /* 65 * Properties 66 */ 67 int get_name(lua_State* L); 68 int get_allowed_buildings(lua_State* L); 69 int get_objectives(lua_State* L); 70 int get_defeated(lua_State* L); 71 int get_messages(lua_State* L); 72 int get_inbox(lua_State* L); 73 int get_color(lua_State* L); 74 int get_team(lua_State* L); 75 int get_tribe(lua_State* L); 76 int set_team(lua_State* L); 77 int get_see_all(lua_State* L); 78 int set_see_all(lua_State* L); 79 80 /* 81 * Lua methods 82 */ 83 int send_message(lua_State* L); 84 int message_box(lua_State* L); 85 int sees_field(lua_State* L); 86 int seen_field(lua_State* L); 87 int allow_buildings(lua_State* L); 88 int forbid_buildings(lua_State* L); 89 int add_objective(lua_State* L); 90 int reveal_fields(lua_State* L); 91 int hide_fields(lua_State* L); 92 int reveal_scenario(lua_State* L); 93 int reveal_campaign(lua_State*); 94 int mark_scenario_as_solved(lua_State* L); 95 int get_ships(lua_State* L); 96 int get_buildings(lua_State* L); 97 int get_suitability(lua_State* L); 98 int allow_workers(lua_State* L); 99 int switchplayer(lua_State* L); 100 int get_produced_wares_count(lua_State* L); 101 int set_attack_forbidden(lua_State* L); 102 int is_attack_forbidden(lua_State* L); 103 104 /* 105 * C methods 106 */ 107 private: 108 void parse_building_list(lua_State*, 109 const Widelands::TribeDescr&, 110 std::vector<Widelands::DescriptionIndex>&); 111 int allow_forbid_buildings(lua_State* L, bool); 112 }; 113 114 class LuaObjective : public LuaGameModuleClass { 115 std::string name_; 116 117 public: 118 LUNA_CLASS_HEAD(LuaObjective); 119 ~LuaObjective()120 ~LuaObjective() override { 121 } 122 123 explicit LuaObjective(const Widelands::Objective& n); 124 LuaObjective() = default; LuaObjective(lua_State * L)125 explicit LuaObjective(lua_State* L) { 126 report_error(L, "Cannot instantiate a '%s' directly!", className); 127 } 128 129 void __persist(lua_State*) override; 130 void __unpersist(lua_State*) override; 131 132 /* 133 * Properties 134 */ 135 int get_name(lua_State* L); 136 int get_title(lua_State* L); 137 int set_title(lua_State* L); 138 int get_body(lua_State* L); 139 int set_body(lua_State* L); 140 int get_visible(lua_State* L); 141 int set_visible(lua_State* L); 142 int get_done(lua_State* L); 143 int set_done(lua_State* L); 144 145 /* 146 * Lua Methods 147 */ 148 int remove(lua_State* L); 149 int __eq(lua_State* L); 150 151 /* 152 * C Methods 153 */ 154 Widelands::Objective& get(lua_State*, Widelands::Game&); 155 }; 156 157 class LuaMessage : public LuaGameModuleClass { 158 Widelands::PlayerNumber player_number_; 159 Widelands::MessageId message_id_; 160 161 public: 162 LUNA_CLASS_HEAD(LuaMessage); ~LuaMessage()163 ~LuaMessage() override { 164 } 165 166 explicit LuaMessage(uint8_t, Widelands::MessageId); LuaMessage()167 LuaMessage() : player_number_(0), message_id_(0) { 168 } LuaMessage(lua_State * L)169 explicit LuaMessage(lua_State* L) { 170 report_error(L, "Cannot instantiate a '%s' directly!", className); 171 } 172 173 void __persist(lua_State*) override; 174 void __unpersist(lua_State*) override; 175 176 /* 177 * Properties 178 */ 179 int get_sent(lua_State* L); 180 int get_title(lua_State* L); 181 int get_body(lua_State* L); 182 int get_field(lua_State* L); 183 int get_status(lua_State* L); 184 int set_status(lua_State* L); 185 int get_heading(lua_State* L); 186 int get_icon_name(lua_State* L); 187 188 /* 189 * Lua Methods 190 */ 191 int __eq(lua_State* L); 192 193 /* 194 * C Methods 195 */ 196 Widelands::Player& get_plr(lua_State* L, Widelands::Game& game); 197 const Widelands::Message& get(lua_State* L, Widelands::Game& game); 198 }; 199 200 void luaopen_wlgame(lua_State*); 201 202 #endif // end of include guard: WL_SCRIPTING_LUA_GAME_H 203 } 204