widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #03182
[Merge] lp:~widelands-dev/widelands/bug-1380286 into lp:widelands
TiborB has proposed merging lp:~widelands-dev/widelands/bug-1380286 into lp:widelands.
Requested reviews:
Widelands Developers (widelands-dev)
Related bugs:
Bug #1380286 in widelands: "Roads of a flag should be accessible in Lua scripting"
https://bugs.launchpad.net/widelands/+bug/1380286
For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1380286/+merge/242975
Adding 3 functions for LUA for flag object to list roads, building (if any) and verify whether the flag is connected to any warehouse
--
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1380286 into lp:widelands.
=== modified file 'src/scripting/lua_bases.h'
--- src/scripting/lua_bases.h 2014-09-10 17:52:49 +0000
+++ src/scripting/lua_bases.h 2014-11-26 20:40:08 +0000
@@ -104,6 +104,10 @@
int conquer(lua_State * L);
int get_workers(lua_State* L);
int get_wares(lua_State* L);
+ int get_roads(lua_State* L);
+ int get_buidling(lua_State* L);
+ int get_has_warehouse(lua_State* L);
+
/*
* C methods
=== modified file 'src/scripting/lua_map.cc'
--- src/scripting/lua_map.cc 2014-10-27 10:14:10 +0000
+++ src/scripting/lua_map.cc 2014-11-26 20:40:08 +0000
@@ -23,6 +23,7 @@
#include "base/deprecated.h"
#include "base/log.h"
+#include "economy/economy.h" //NOCOM needed?
#include "economy/wares_queue.h"
#include "graphic/graphic.h"
#include "logic/carrier.h"
@@ -2343,6 +2344,9 @@
{nullptr, nullptr},
};
const PropertyType<LuaFlag> LuaFlag::Properties[] = {
+ PROP_RO(LuaFlag, roads),
+ PROP_RO(LuaFlag, building),
+ PROP_RO(LuaFlag, has_warehouse),
{nullptr, nullptr, nullptr},
};
@@ -2352,7 +2356,75 @@
PROPERTIES
==========================================================
*/
-
+//NOCOM
+/* RST
+ .. attribute:: roads
+
+ (RO) Array of roads leading to the flag. Directions
+ can be tr,r,br,bl,l and tl
+
+ :returns: The array of 'direction:road', if any
+*/
+int LuaFlag::get_roads(lua_State * L) {
+
+ const std::vector<std::string> directions = {"tr", "r", "br", "bl", "l", "tl"};
+
+ lua_newtable(L);
+
+ EditorGameBase & egbase = get_egbase(L);
+ Flag * f = get(L, egbase);
+
+ for (uint32_t i=1; i<=6; i++){
+ if (f->get_road(i) != nullptr) {
+ lua_pushstring(L,directions.at(i-1));
+ upcasted_map_object_to_lua(L, f->get_road(i));
+ lua_rawset(L,-3);
+ }
+ }
+ return 1;
+
+}
+/* RST
+ .. attribute:: building
+
+ (RO) building belonging to the flag
+*/
+int LuaFlag::get_building(lua_State * L) {
+
+ EditorGameBase & egbase = get_egbase(L);
+ Flag * f = get(L, egbase);
+
+ PlayerImmovable * building = f->get_building();
+ if (!building) {
+ return 0;
+ } else {
+ upcasted_map_object_to_lua(L, building);
+ }
+ return 1;
+
+}
+/* RST
+ .. attribute:: has_warehouse
+
+ (RO) does the economy has a warehouse? (~is a flag
+ connected to any warehouse?)
+
+
+ : returns number of warehouses, or nil if no warehouse
+*/
+int LuaFlag::get_has_warehouse(lua_State * L) {
+
+ EditorGameBase & egbase = get_egbase(L);
+ Flag * f = get(L, egbase);
+ int32_t warehouses = f->get_economy()->warehouses().size();
+
+ if (warehouses==0) {
+ return 0;
+ } else {
+ lua_pushint32(L,warehouses);
+ }
+ return 1;
+}
/*
==========================================================
LUA METHODS
@@ -3660,7 +3732,8 @@
report_error(L, "Illegal amount: %i, must be >= 0 and <= %i", amount, max_amount);
field->set_resources(res, amount);
-
+ field->set_starting_res_amount(amount); //NOCOM Bug #1281823
+
return 0;
}
=== modified file 'src/scripting/lua_map.h'
--- src/scripting/lua_map.h 2014-09-14 11:31:58 +0000
+++ src/scripting/lua_map.h 2014-11-26 20:40:08 +0000
@@ -596,13 +596,16 @@
/*
* Properties
*/
-
+ int get_roads(lua_State *);
+ int get_building(lua_State *);
+ int get_has_warehouse(lua_State *);
/*
* Lua Methods
*/
int set_wares(lua_State *);
int get_wares(lua_State *);
+
/*
* C Methods
*/
Follow ups
-
[Merge] lp:~widelands-dev/widelands/bug-1380286 into lp:widelands
From: noreply, 2015-02-12
-
Re: [Merge] lp:~widelands-dev/widelands/bug-1380286 into lp:widelands
From: SirVer, 2015-02-12
-
Re: [Merge] lp:~widelands-dev/widelands/bug-1380286 into lp:widelands
From: GunChleoc, 2015-02-05
-
Re: [Merge] lp:~widelands-dev/widelands/bug-1380286 into lp:widelands
From: TiborB, 2015-02-03
-
Re: [Merge] lp:~widelands-dev/widelands/bug-1380286 into lp:widelands
From: TiborB, 2014-12-11
-
Re: [Merge] lp:~widelands-dev/widelands/bug-1380286 into lp:widelands
From: GunChleoc, 2014-12-04
-
Re: [Merge] lp:~widelands-dev/widelands/bug-1380286 into lp:widelands
From: TiborB, 2014-12-04
-
Re: [Merge] lp:~widelands-dev/widelands/bug-1380286 into lp:widelands
From: TiborB, 2014-12-04
-
Re: [Merge] lp:~widelands-dev/widelands/bug-1380286 into lp:widelands
From: SirVer, 2014-12-04
-
Re: [Merge] lp:~widelands-dev/widelands/bug-1380286 into lp:widelands
From: TiborB, 2014-12-04
-
Re: [Merge] lp:~widelands-dev/widelands/bug-1380286 into lp:widelands
From: SirVer, 2014-12-04
-
Re: [Merge] lp:~widelands-dev/widelands/bug-1380286 into lp:widelands
From: wl-zocker, 2014-11-27
-
Re: [Merge] lp:~widelands-dev/widelands/bug-1380286 into lp:widelands
From: TiborB, 2014-11-27
-
Re: [Merge] lp:~widelands-dev/widelands/bug-1380286 into lp:widelands
From: GunChleoc, 2014-11-27
-
Re: [Merge] lp:~widelands-dev/widelands/bug-1380286 into lp:widelands
From: TiborB, 2014-11-27
-
Re: [Merge] lp:~widelands-dev/widelands/bug-1380286 into lp:widelands
From: GunChleoc, 2014-11-27