Author: cazfi Date: Mon Aug 17 05:47:52 2015 New Revision: 29564 URL: http://svn.gna.org/viewcvs/freeciv?rev=29564&view=rev Log: Lua's give_technology() can control what kind of penalty; freecost, conquercost, diplbulbcost, or custom gets applied.
Reported by Jacob Nevins <jtn> See bug #22160 Modified: branches/S2_6/data/alien/script.lua branches/S2_6/data/default/default.lua branches/S2_6/data/multiplayer/script.lua branches/S2_6/server/scripting/api_server_edit.c branches/S2_6/server/scripting/api_server_edit.h branches/S2_6/server/scripting/tolua_server.pkg Modified: branches/S2_6/data/alien/script.lua URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/data/alien/script.lua?rev=29564&r1=29563&r2=29564&view=diff ============================================================================== --- branches/S2_6/data/alien/script.lua (original) +++ branches/S2_6/data/alien/script.lua Mon Aug 17 05:47:52 2015 @@ -24,7 +24,7 @@ -- Get a tech from entering a hut. function alien_hut_get_tech(unit) local owner = unit.owner - local tech = owner:give_technology(nil, "hut") + local tech = owner:give_technology(nil, -1, "hut") if tech then notify.event(owner, unit.tile, E.HUT_TECH, Modified: branches/S2_6/data/default/default.lua URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/data/default/default.lua?rev=29564&r1=29563&r2=29564&view=diff ============================================================================== --- branches/S2_6/data/default/default.lua (original) +++ branches/S2_6/data/default/default.lua Mon Aug 17 05:47:52 2015 @@ -33,7 +33,7 @@ -- Get a tech from entering a hut. function default_hut_get_tech(unit) local owner = unit.owner - local tech = owner:give_technology(nil, "hut") + local tech = owner:give_technology(nil, -1, "hut") if tech then notify.event(owner, unit.tile, E.HUT_TECH, Modified: branches/S2_6/data/multiplayer/script.lua URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/data/multiplayer/script.lua?rev=29564&r1=29563&r2=29564&view=diff ============================================================================== --- branches/S2_6/data/multiplayer/script.lua (original) +++ branches/S2_6/data/multiplayer/script.lua Mon Aug 17 05:47:52 2015 @@ -34,8 +34,8 @@ if player:give_technology(find.tech_type("Theory of Evolution"), "researched") then -- Give the player two free advances. - gained[0] = player:give_technology(nil, "researched") - gained[1] = player:give_technology(nil, "researched") + gained[0] = player:give_technology(nil, 0, "researched") + gained[1] = player:give_technology(nil, 0, "researched") -- Notify the player. Include the tech names in a way that makes it -- look natural no matter if each tech is announced or not. @@ -105,7 +105,7 @@ -- Give the player a free advance. -- This will give a free advance for each player that shares research. - gained = player:give_technology(nil, "researched") + gained = player:give_technology(nil, -1, "researched") -- Notify the player. Include the tech names in a way that makes it -- look natural no matter if each tech is announced or not. Modified: branches/S2_6/server/scripting/api_server_edit.c URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/scripting/api_server_edit.c?rev=29564&r1=29563&r2=29564&view=diff ============================================================================== --- branches/S2_6/server/scripting/api_server_edit.c (original) +++ branches/S2_6/server/scripting/api_server_edit.c Mon Aug 17 05:47:52 2015 @@ -272,7 +272,7 @@ sends script signal "tech_researched" with the given reason *****************************************************************************/ Tech_Type *api_edit_give_technology(lua_State *L, Player *pplayer, - Tech_Type *ptech, const char *reason) + Tech_Type *ptech, int cost, const char *reason) { struct research *presearch; Tech_type_id id; @@ -280,6 +280,7 @@ LUASCRIPT_CHECK_STATE(L, NULL); LUASCRIPT_CHECK_ARG_NIL(L, pplayer, 2, Player, NULL); + LUASCRIPT_CHECK_ARG(L, cost >= -3, 4, "Unknown give_tech() cost value", NULL); presearch = research_get(pplayer); if (ptech) { @@ -299,7 +300,19 @@ if (is_future_tech(id) || research_invention_state(presearch, id) != TECH_KNOWN) { - research_apply_penalty(presearch, id, game.server.freecost); + if (cost < 0) { + if (cost == -1) { + cost = game.server.freecost; + } else if (cost == -2) { + cost = game.server.conquercost; + } else if (cost == -3) { + cost = game.server.diplbulbcost; + } else { + + cost = 0; + } + } + research_apply_penalty(presearch, id, cost); found_new_tech(presearch, id, FALSE, TRUE); result = advance_by_number(id); script_tech_learned(presearch, pplayer, result, reason); Modified: branches/S2_6/server/scripting/api_server_edit.h URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/scripting/api_server_edit.h?rev=29564&r1=29563&r2=29564&view=diff ============================================================================== --- branches/S2_6/server/scripting/api_server_edit.h (original) +++ branches/S2_6/server/scripting/api_server_edit.h Mon Aug 17 05:47:52 2015 @@ -48,7 +48,8 @@ Nation_Type *pnation, const char *ai); void api_edit_change_gold(lua_State *L, Player *pplayer, int amount); Tech_Type *api_edit_give_technology(lua_State *L, Player *pplayer, - Tech_Type *ptech, const char *reason); + Tech_Type *ptech, int cost, + const char *reason); bool api_edit_trait_mod(lua_State *L, Player *pplayer, const char *trait_name, const int mod); Modified: branches/S2_6/server/scripting/tolua_server.pkg URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/scripting/tolua_server.pkg?rev=29564&r1=29563&r2=29564&view=diff ============================================================================== --- branches/S2_6/server/scripting/tolua_server.pkg (original) +++ branches/S2_6/server/scripting/tolua_server.pkg Mon Aug 17 05:47:52 2015 @@ -118,9 +118,14 @@ const char *ai); void api_edit_change_gold @ change_gold (lua_State *L, Player *pplayer, int amount); + /* cost: + * 0 or above - The exact cost % to apply + * -1 - Apply freecost + * -2 - Apply conquercost + * -3 - Apply diplbulbcost */ Tech_Type *api_edit_give_technology @ give_technology (lua_State *L, Player *pplayer, Tech_Type *ptech, - const char *reason); + int cost, const char *reason); bool api_edit_trait_mod @ trait_mod (lua_State *L, Player *pplayer, const char *trait_name, const int mod); @@ -184,8 +189,8 @@ edit.change_gold(pplayer, amount) end -function give_technology(player, tech, reason) - return edit.give_technology(player, tech, reason) +function give_technology(player, tech, cost, reason) + return edit.give_technology(player, tech, cost, reason) end function trait_mod(player, trait, mod) @@ -224,8 +229,8 @@ edit.change_gold(self, amount) end -function Player:give_technology(tech, reason) - return edit.give_technology(self, tech, reason) +function Player:give_technology(tech, cost, reason) + return edit.give_technology(self, tech, cost, reason) end function Player:trait_mod(trait, mod) _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits