widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #16415
Re: [Merge] lp:~widelands-dev/widelands/peaceful into lp:widelands
Code LGTM so far except for a few nits, not tested.
I think we should also add some code to the fieldactions to forbid attacking a building, and the AI will need changing as well.
Diff comments:
> === modified file 'data/campaigns/fri02.wmf/scripting/mission_thread.lua'
> --- data/campaigns/fri02.wmf/scripting/mission_thread.lua 2018-09-29 08:43:57 +0000
> +++ data/campaigns/fri02.wmf/scripting/mission_thread.lua 2019-03-29 10:22:28 +0000
> @@ -333,13 +335,27 @@
> include "map:scripting/starting_conditions.lua"
> sleep(5000)
>
> - p1.team = 1
> - p2.team = 1
> - p3.team = 2
> --- TODO: instead of alliances, just forbid certain players to attack each other:
> --- · Beginning: forbid 1>2, 2>1, 2>3
> --- · Refusing alliance: forbid only 2>3
> --- · Accepting alliance: first unchanged, after p3 defeated: allow all
> + p1:set_attack_forbidden(2, true)
> + p2:set_attack_forbidden(1, true)
> + p2:set_attack_forbidden(3, true)
> + run(function()
> + while true do
> + local conquered = (#p3:get_buildings("empire_sentry") +
> + #p3:get_buildings("empire_blockhouse") +
> + #p3:get_buildings("empire_outpost") +
> + #p3:get_buildings("empire_barrier") +
> + #p3:get_buildings("empire_tower") +
> + #p3:get_buildings("empire_fortress") +
> + #p3:get_buildings("empire_castle") -
> + #p2:get_buildings("barbarians_sentry") -
> + #p2:get_buildings("barbarians_barrier") -
> + #p2:get_buildings("barbarians_tower") -
> + #p2:get_buildings("barbarians_fortress") -
> + #p2:get_buildings("barbarians_citadel"))
> + p2:set_attack_forbidden(3, conquered <= 0)
The loop will keep running once this has been set. You could do a repeat... until instead, or add a break statement.
> + sleep(6913)
> + end
> + end)
>
> campaign_message_box(intro_3)
> local o = add_campaign_objective(obj_new_home)
>
> === modified file 'src/network/network_protocol.h'
> --- src/network/network_protocol.h 2019-02-23 11:00:49 +0000
> +++ src/network/network_protocol.h 2019-03-29 10:22:28 +0000
> @@ -429,6 +429,14 @@
> NETCMD_SYSTEM_MESSAGE_CODE = 32,
>
> /**
> + * Sent by the host to toggle peaceful mode.
> + *
> + * Attached data is:
> + * \li uint8_t: 1 if peaceful mode is enabled, 0 otherwise
> + */
> + NETCMD_PEACEFUL_MODE = 33,
We have a new command - bump the protocol version
> +
> + /**
> * Sent by the metaserver to a freshly opened game to check connectability
> */
> NETCMD_METASERVER_PING = 64
>
> === modified file 'src/scripting/lua_game.cc'
> --- src/scripting/lua_game.cc 2019-03-09 08:58:52 +0000
> +++ src/scripting/lua_game.cc 2019-03-29 10:22:28 +0000
> @@ -875,6 +877,39 @@
> return 1;
> }
>
> +/* RST
> + .. method:: is_attack_forbidden(who)
> +
> + Returns true if this player is currently forbidden to attack the player with the specified
> + player number. Note that the return value `false` does not necessarily mean that this
> + player *can* attack the other player, as they might for example be in the same team.
> +
> + :arg who: player number of the player to query
> + :type who: :class:`int`
> + :rtype: :class:`boolean`
> +*/
> +int LuaPlayer::is_attack_forbidden(lua_State* L) {
> + lua_pushboolean(L, get(L, get_egbase(L)).is_attack_forbidden(luaL_checkinteger(L, 2)));
> + return 1;
> +}
> +
> +/* RST
> + .. method:: set_attack_forbidden(who, forbid)
> +
> + Sets whether this player is forbidden to attack the player with the specified
> + player number. Note that setting this to `false` does not necessarily mean that this
> + player *can* attack the other player, as they might for example be in the same team.
> +
> + :arg who: player number of the player to query
> + :type who: :class:`int`
> + :arg forbid: Whether to allow or forbid attacks
> + :type forbid: :class:`boolean`
> +*/
> +int LuaPlayer::set_attack_forbidden(lua_State* L) {
Please add a test to the test suite for the 2 new functions
> + get(L, get_egbase(L)).set_attack_forbidden(luaL_checkinteger(L, 2), luaL_checkboolean(L, 3));
> + return 0;
> +}
> +
> /*
> ==========================================================
> C METHODS
--
https://code.launchpad.net/~widelands-dev/widelands/peaceful/+merge/365273
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/peaceful into lp:widelands.
References