--[[ Hermit hut enter ================ ]] mtn_terrain = find.terrain ("Mountains") function count_mtns() mtn_total = 0 -- global for tile in whole_map_iterate () do if tile.terrain == mtn_terrain then mtn_total = mtn_total +1 end end end signal.connect("map_generated", "count_mtns") function new_hermit (turn, year) if mtn_total > 0 and year < 1000 and math.floor (random (1,3)) == 1 then local mtn_count = math.floor (random (1, mtn_total)) for tile in whole_map_iterate () do if tile.terrain == mtn_terrain then mtn_count = mtn_count -1 if mtn_count == 0 then if tile:num_units () == 0 and not works_nearby (tile) then edit.create_extra (tile, "Hut" ) end return end end end end end signal.connect("turn_started", "new_hermit") -- assumes the tech has already been gotten - so just reports function hermit_tech(unit, tech) local player, tile = unit.owner, unit.tile local tech_name = tech:name_translation() notify.event(player, tile, E.HUT_TECH, _("A hermit lived here. He slipped away but left behind his work on %s.") , tech_name) notify.research(player, false, E.TECH_GAIN, -- /* TRANS: One player got tech for the whole team. */ _("The %s has been given %s by a hermit."), player.nation:plural_translation(), tech_name) notify.research_embassies(player, E.TECH_EMBASSY, -- /* TRANS: first %s is leader or team name */ _("%s has acquired %s from a hermit."), player:research_name_translation(), tech_name) end; function works_nearby (tile) for near_tile in tile:circle_iterate (1) do if near_tile:has_extra ("Irrigation") then return true end end for near_tile in tile:circle_iterate (2) do if near_tile:has_extra ("Mine" ) or near_tile:has_extra ("Road" ) or near_tile:has_extra ("Fort" ) or near_tile:has_extra ("Airstrip") then return true end end end function nobody_home (context) local unit = context.unit local player, tile = unit.owner, unit.tile notify.event(player, tile, E.HUT_BARB_CITY_NEAR, _("A hermit may have lived here, but not now.") ) end function hermit (context) local unit = context.unit local player, tile = unit.owner, unit.tile local tech = edit.give_tech (player, nil, -1, false, "hermit") if tech then return hermit_tech (unit, tech) else return 25 end end stolen = _("A thief stole your purse. ") thief = function (context, gold) local unit = context.unit local player, tile = unit.owner, unit.tile if gold > 0 then player:change_gold(-gold) notify.event(player, tile, E.HUT_GOLD, stolen.. PL_("You lost %d gold.", "You lost %d gold.", gold), gold) else notify.event(player, tile, E.HUT_GOLD, stolen.. _("Luckily there was nothing in it.") ) end end; function _deflua_hut_ruleset_context (self, unit) local context = self:reset (unit) local MPF, tail = context._MPF, context._tail if unit.tile.terrain == mtn_terrain then context.city_radius_sq = 5 -- actual city radius context.use_number = thief if context:_near_city () or works_nearby (unit.tile) then context:_set_point (nobody_home, 1) else context:_set_point (hermit, 3) context:_set_point ( math.floor (random (0, math.min (5,unit.owner:gold()))), 1) end else context:_set_point ( 25, 1) context:_set_point ( 50, 3) context:_set_point (100, 1) -- context:_set_point (MPF.technology, 3) context:_set_point (MPF.mercenary, 2) context:_set_point (MPF.barbarians, 1) context:_set_point (MPF.city, 1) end return context end --[[ End hermit hut enter ==================== ]]