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_BASES_H 21 #define WL_SCRIPTING_LUA_BASES_H 22 23 #include "logic/editor_game_base.h" 24 #include "logic/player.h" 25 #include "scripting/lua.h" 26 #include "scripting/luna.h" 27 28 namespace LuaBases { 29 30 /* 31 * Base class for all classes in wl.base 32 */ 33 class LuaBasesModuleClass : public LunaClass { 34 public: get_modulename()35 const char* get_modulename() override { 36 return "bases"; 37 } 38 }; 39 40 class LuaEditorGameBase : public LuaBasesModuleClass { 41 public: 42 LUNA_CLASS_HEAD(LuaEditorGameBase); 43 LuaEditorGameBase()44 LuaEditorGameBase() { 45 } LuaEditorGameBase(lua_State * L)46 explicit LuaEditorGameBase(lua_State* L) { 47 report_error(L, "Cannot instantiate a 'EditorGameBase' directly!"); 48 } ~LuaEditorGameBase()49 ~LuaEditorGameBase() override { 50 } 51 52 void __persist(lua_State* L) override; 53 void __unpersist(lua_State* L) override; 54 55 /* 56 * Properties 57 */ 58 int get_map(lua_State*); 59 int get_players(lua_State*); 60 61 /* 62 * Lua methods 63 */ 64 int get_immovable_description(lua_State* L); 65 int get_building_description(lua_State* L); 66 int get_tribe_description(lua_State* L); 67 int get_ware_description(lua_State* L); 68 int get_worker_description(lua_State* L); 69 int get_resource_description(lua_State* L); 70 int get_terrain_description(lua_State* L); 71 int save_campaign_data(lua_State* L); 72 int read_campaign_data(lua_State* L); 73 int set_loading_message(lua_State*); 74 75 /* 76 * C methods 77 */ 78 }; 79 80 class LuaPlayerBase : public LuaBasesModuleClass { 81 Widelands::PlayerNumber player_number_; 82 enum { NONE = -1 }; 83 84 public: 85 LUNA_CLASS_HEAD(LuaPlayerBase); 86 LuaPlayerBase()87 LuaPlayerBase() : player_number_(NONE) { 88 } LuaPlayerBase(lua_State * L)89 explicit LuaPlayerBase(lua_State* L) : player_number_(NONE) { 90 report_error(L, "Cannot instantiate a 'PlayerBase' directly!"); 91 } LuaPlayerBase(Widelands::PlayerNumber n)92 explicit LuaPlayerBase(Widelands::PlayerNumber n) { 93 player_number_ = n; 94 } ~LuaPlayerBase()95 ~LuaPlayerBase() override { 96 } 97 98 void __persist(lua_State* L) override; 99 void __unpersist(lua_State* L) override; 100 101 /* 102 * Properties 103 */ 104 int get_number(lua_State* L); 105 int get_tribe_name(lua_State* L); 106 107 /* 108 * Lua methods 109 */ 110 int __eq(lua_State* L); 111 int __tostring(lua_State* L); 112 int place_flag(lua_State* L); 113 int place_road(lua_State* L); 114 int place_building(lua_State* L); 115 int place_ship(lua_State* L); 116 int conquer(lua_State* L); 117 int get_workers(lua_State* L); 118 int get_wares(lua_State* L); 119 120 /* 121 * C methods 122 */ 123 Widelands::Player& get(lua_State* L, Widelands::EditorGameBase&); 124 125 protected: player_number()126 inline Widelands::PlayerNumber player_number() { 127 return player_number_; 128 } 129 }; 130 131 void luaopen_wlbases(lua_State*); 132 } // namespace LuaBases 133 134 #endif // end of include guard: WL_SCRIPTING_LUA_BASES_H 135