MarkMcWire
Joined: 2017-02-08, 21:06
Posts: 204
Widelands-Forum-Junkie
Location: Eisenach, Germany
|
Posted at: Yesterday 16:22
I've introduced a new feature for the European tribe. The time-dependent and more important ware-dependent activation of buildings. I've incorporated and tested it in the "Headquarters" starting condition and it works pretty well.
There is the AI hint "prohibited_till =", but in rare cases the AI ignores it or the effect is to small. Because its time-dependent but ignores the actual economical status. This leads to buildings being build or upgraded where it is not necessary, which means that building materials for other essential buildings are lacking and, in extreme cases, the entire economy can hang up.
Through the Lua script, I can tell that a certain building like charcoal will only be unlocked when there is enough log and at the same time there is a need for coal.
So you can control the economy of the AI very precisely. Better than the AI hints.
-- =======================================================================
-- Headquarters Starting Conditions for Europeans
-- =======================================================================
include "scripting/infrastructure.lua"
include "scripting/debug.lua"
push_textdomain("tribes")
init = {
-- TRANSLATORS: This is the name of a starting condition
descname = _ "Headquarters",
-- TRANSLATORS: This is the tooltip for the "Headquarters" starting condition
tooltip = _"Start the game with your headquarters only",
func = function(plr, shared_in_start)
local sf = wl.Game().map.player_slots[plr.number].starting_field
if shared_in_start then
sf = shared_in_start
else
plr:allow_workers("all")
end
plr:forbid_buildings("all")
plr:allow_buildings{"europeans_guardhouse", "europeans_tower", "europeans_castle", "europeans_port", "europeans_warehouse_basic"}
plr:allow_buildings{"europeans_well_basic", "europeans_lumberjacks_house_basic", "europeans_foresters_house_basic", "europeans_quarry_basic", "europeans_reed_yard"}
plr:allow_buildings{"europeans_fishers_house_basic", "europeans_hunters_house_basic", "europeans_gamekeepers_hut", "europeans_beekeepers_house", "europeans_farm_basic"}
prefilled_buildings(plr, { "europeans_headquarters", sf.x, sf.y,
wares = {
water = 256,
log = 256,
granite = 64,
coal = 64,
planks = 64,
reed = 64,
cloth = 48,
marble = 48,
quartz = 48,
iron = 32,
corn = 32,
grout = 32,
brick = 32,
spider_silk = 16,
spidercloth = 16,
diamond = 16,
},
workers = {
europeans_carrier = 32,
europeans_farmer_basic = 24,
europeans_builder = 12,
europeans_miner_basic = 12,
europeans_trainer = 6,
europeans_lumberjack_basic = 6,
europeans_forester_basic = 4,
europeans_carpenter_basic = 2,
europeans_stonecutter_basic = 2,
europeans_stonemason_basic = 2,
europeans_charcoal_burner_basic = 2,
europeans_hunter_basic = 2,
europeans_fisher_basic = 2,
europeans_fishbreeder = 2,
europeans_miller_basic = 2,
europeans_baker_basic = 2,
europeans_smoker_basic = 2,
europeans_brewer_basic = 2,
europeans_breeder_normal = 2,
europeans_weaver_basic = 2,
europeans_smelter_basic = 2,
europeans_smith_basic = 2,
europeans_shipwright = 2,
europeans_beekeeper = 1,
europeans_gamekeeper = 1,
europeans_geologist = 1
},
soldiers = {
[{0,0,0,0}] = 32,
}
})
for i = 1, 120 do
-- Delay of 5 min between actions
sleep(300000)
-- Ware-dependent activation
if plr:get_wares("marble") < 8 then
plr:allow_buildings{"europeans_quarry_normal"}
end
if plr:get_wares("quartz") < 4 then
plr:allow_buildings{"europeans_quarry_advanced"}
end
if plr:get_wares("diamond") < 4 then
plr:allow_buildings{"europeans_quarry_advanced"}
end
if plr:get_wares("log") > 8 and plr:get_wares("planks") < 16 then
plr:allow_buildings{"europeans_sawmill_basic"}
end
if plr:get_wares("log") > 16 and plr:get_wares("coal") < 8 then
plr:allow_buildings{"europeans_charcoal_kiln_basic"}
end
if plr:get_wares("coal") > 8 and plr:get_wares("ore") > 8 and plr:get_wares("iron") < 8 then
plr:allow_buildings{"europeans_smelting_works_basic"}
end
if plr:get_wares("water") > 8 and plr:get_wares("clay") < 16 then
plr:allow_buildings{"europeans_clay_pit"}
end
if plr:get_wares("granite") > 8 and plr:get_wares("grout") < 16 then
plr:allow_buildings{"europeans_lime_kiln"}
end
if plr:get_wares("clay") > 8 and plr:get_wares("brick") < 16 then
plr:allow_buildings{"europeans_lime_kiln"}
end
if plr:get_wares("marble") > 8 and plr:get_wares("marble_column") < 4 then
plr:allow_buildings{"europeans_stonemasons_house"}
end
if plr:get_wares("water") > 8 and plr:get_wares("reed") < 8 then
plr:allow_buildings{"europeans_reed_yard"}
end
if plr:get_wares("water") > 8 and plr:get_wares("barley") < 8 then
plr:allow_buildings{"europeans_farm_basic"}
end
if plr:get_wares("water") > 8 and plr:get_wares("corn") < 8 then
plr:allow_buildings{"europeans_farm_level_1"}
end
if plr:get_wares("water") > 16 and plr:get_wares("blackroot") < 8 then
plr:allow_buildings{"europeans_farm_level_2"}
end
if plr:get_wares("water") > 32 and plr:get_wares("fruit") < 8 then
plr:allow_buildings{"europeans_farm_level_3"}
end
if plr:get_wares("corn") > 8 and plr:get_wares("spider_silk") < 8 then
plr:allow_buildings{"europeans_spiderfarm"}
end
if plr:get_wares("blackroot") > 8 and plr:get_wares("wool") < 8 then
plr:allow_buildings{"europeans_sheepfarm"}
end
if plr:get_wares("reed") > 16 and plr:get_wares("cloth") < 16 then
plr:allow_buildings{"europeans_weaving_mill_basic"}
end
if plr:get_wares("spider_silk") > 8 and plr:get_wares("spidercloth") < 8 then
plr:allow_buildings{"europeans_weaving_mill_normal"}
end
if plr:get_wares("wool") > 8 and plr:get_wares("armor") < 8 then
plr:allow_buildings{"europeans_weaving_mill_advanced"}
end
if plr:get_wares("barley") > 8 and plr:get_wares("beer") < 8 then
plr:allow_buildings{"europeans_brewery_basic"}
end
if plr:get_wares("barley") > 8 and plr:get_wares("mead") < 8 then
plr:allow_buildings{"europeans_brewery_normal", "europeans_beekeepers_house"}
end
if plr:get_wares("grape") > 8 and plr:get_wares("fruit") > 8 and plr:get_wares("wine") < 8 then
plr:allow_buildings{"europeans_brewery_winery", "europeans_brewery_advanced"}
end
if plr:get_wares("rye") > 8 and plr:get_wares("wheat") > 8 and plr:get_wares("flour") < 8 then
plr:allow_buildings{"europeans_mill_basic"}
end
if plr:get_wares("flour") > 8 and plr:get_wares("meat") > 8 and plr:get_wares("ration") < 8 then
plr:allow_buildings{"europeans_tavern_basic", "europeans_tavern_level_1", "europeans_tavern_level_2"}
end
if plr:get_wares("flour") > 8 and plr:get_wares("meat") > 8 and plr:get_wares("snack") < 8 then
plr:allow_buildings{"europeans_tavern_level_3", "europeans_tavern_level_4", "europeans_tavern_level_5"}
end
if plr:get_wares("flour") > 8 and plr:get_wares("meat") > 8 and plr:get_wares("meal") < 8 then
plr:allow_buildings{"europeans_inn_basic", "europeans_inn_level_1", "europeans_inn_level_2"}
end
if plr:get_wares("beer") > 8 and plr:get_wares("ration") > 8 and plr:get_wares("coal") < 8 then
plr:allow_buildings{"europeans_coalmine_basic", "europeans_coalmine_level_1", "europeans_coalmine_level_2"}
end
if plr:get_wares("beer") > 8 and plr:get_wares("ration") > 8 and plr:get_wares("iron") < 8 then
plr:allow_buildings{"europeans_goldmine_basic", "europeans_goldmine_level_1", "europeans_goldmine_level_2", "europeans_ironmine_basic", "europeans_ironmine_level_1", "europeans_ironmine_level_2"}
end
if plr:get_wares("mead") > 8 and plr:get_wares("snack") > 8 and plr:get_wares("coal") < 8 then
plr:allow_buildings{"europeans_coalmine_level_3", "europeans_coalmine_level_4"}
end
if plr:get_wares("mead") > 8 and plr:get_wares("snack") > 8 and plr:get_wares("iron") < 8 then
plr:allow_buildings{"europeans_goldmine_level_3", "europeans_goldmine_level_4", "europeans_ironmine_level_3", "europeans_ironmine_level_4"}
end
if plr:get_wares("wine") > 8 and plr:get_wares("meal") > 8 and plr:get_wares("coal") < 8 then
plr:allow_buildings{"europeans_coalmine_level_5"}
end
if plr:get_wares("wine") > 8 and plr:get_wares("meal") > 8 and plr:get_wares("iron") < 8 then
plr:allow_buildings{"europeans_goldmine_level_5", "europeans_ironmine_level_5"}
end
-- Time-dependent activation
if i > 12 then
plr:allow_buildings{"europeans_smithy_basic", "europeans_smithy_level_1", "europeans_smithy_level_2", "europeans_recruitement_center_basic", "europeans_ferry_yard_basic", "europeans_shipyard_basic"}
end
if i > 24 then
plr:allow_buildings{"europeans_sawmill_normal", "europeans_charcoal_kiln_normal", "europeans_smelting_works_normal", "europeans_mill_normal", "europeans_well_normal", "europeans_scouts_house_basic"}
end
if i > 36 then
plr:allow_buildings{"europeans_smithy_level_3", "europeans_trainingscamp_basic", "europeans_labyrinth"}
end
if i > 48 then
plr:allow_buildings{"europeans_smithy_level_4", "europeans_smithy_level_5", "europeans_smithy_level_6", "europeans_guardhall", "europeans_trainingscamp_normal", "europeans_arena"}
end
if i > 60 then
plr:allow_buildings{"europeans_smithy_level_7", "europeans_smithy_level_8", "europeans_smithy_level_9", "europeans_dungeon", "europeans_trainingscamp_advanced", "europeans_colosseum"}
end
if i > 72 then
plr:allow_buildings{"europeans_sawmill_advanced", "europeans_charcoal_kiln_advanced", "europeans_smelting_works_advanced", "europeans_mill_advanced", "europeans_well_advanced"}
end
if i > 84 then
plr:allow_buildings{"europeans_lumberjacks_house_normal", "europeans_foresters_house_normal", "europeans_hunters_house_normal", "europeans_fishers_house_normal", "europeans_scouts_house_normal", "europeans_shipyard_normal"}
end
if i > 96 then
plr:allow_buildings{"europeans_lumberjacks_house_advanced", "europeans_foresters_house_advanced", "europeans_hunters_house_advanced", "europeans_fishers_house_advanced", "europeans_scouts_house_advanced", "europeans_shipyard_advanced"}
end
if i > 108 then
plr:allow_buildings("all")
end
end
end
}
pop_textdomain()
return init
Edited: Yesterday 19:50
My widelands project: https://github.com/MarkMcWire/widelands
Top
Quote
|