Make AI less likely to stop building wonder
[freeciv.git] / data / alien / script.lua
blob69b9784410df20b3b2f27076326a8b8510f41876
1 -- Freeciv - Copyright (C) 2007 - The Freeciv Project
2 -- This program is free software; you can redistribute it and/or modify
3 -- it under the terms of the GNU General Public License as published by
4 -- the Free Software Foundation; either version 2, or (at your option)
5 -- any later version.
6 --
7 -- This program is distributed in the hope that it will be useful,
8 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
9 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 -- GNU General Public License for more details.
12 -- This file is for lua-functionality that is specific to a given
13 -- ruleset. When freeciv loads a ruleset, it also loads script
14 -- file called 'default.lua'. The one loaded if your ruleset
15 -- does not provide an override is default/default.lua.
17 -----------------------------------------------------------------------------------------------------
18 -- default.lua callback overrides
20 -- Get gold from entering a hut.
21 function alien_hut_get_gold(unit, gold)
22 local owner = unit.owner
24 notify.event(owner, unit.tile, E.HUT_GOLD, PL_("It was a safe containing %d gold.",
25 "It was a safe containing %d gold.", gold),
26 gold)
27 owner:change_gold(gold)
28 end
30 -- Get a tech from entering a hut.
31 function alien_hut_get_tech(unit)
32 local owner = unit.owner
33 local tech = owner:give_tech(nil, -1, false, "hut")
35 if tech then
36 notify.event(owner, unit.tile, E.HUT_TECH,
37 _("There was a datapod containing research info about %s."),
38 tech:name_translation())
39 notify.research(owner, false, E.TECH_GAIN,
40 _("%s found datapod containing research info about %s."),
41 owner.nation:plural_translation(),
42 tech:name_translation())
43 notify.research_embassies(owner, E.HUT_TECH,
44 _("The %s have acquired %s from Space Capsule they found."),
45 owner:research_name_translation(),
46 tech:name_translation())
47 return true
48 else
49 return false
50 end
51 end
53 -- Get new city from hut
54 function alien_hut_get_city(unit)
55 local owner = unit.owner
57 if unit:is_on_possible_city_tile() then
58 owner:create_city(unit.tile, "")
59 notify.event(owner, unit.tile, E.HUT_CITY,
60 _("You found a base starting kit."))
61 return true
62 else
63 return false
64 end
65 end
67 -- Get barbarians from hut, unless close to a city, king enters, or
68 -- barbarians are disabled
69 -- Unit may die: returns true if unit is alive
70 function alien_hut_get_barbarians(unit)
71 local tile = unit.tile
72 local type = unit.utype
73 local owner = unit.owner
75 if server.setting.get("barbarians") == "DISABLED"
76 or unit.tile:city_exists_within_max_city_map(true)
77 or type:has_flag('Gameloss') then
78 notify.event(owner, unit.tile, E.HUT_BARB_CITY_NEAR,
79 _("The Space Capsule was already scavenged by someone."))
80 return true
81 end
83 local alive = tile:unleash_barbarians()
84 if alive then
85 notify.event(owner, tile, E.HUT_BARB,
86 _("It was a trap! Set by the outcasts."));
87 else
88 notify.event(owner, tile, E.HUT_BARB_KILLED,
89 _("Your %s has been killed by outcasts!"),
90 type:name_translation());
91 end
92 return alive
93 end
95 -- Randomly choose a hut event
96 function alien_hut_enter_callback(unit)
97 local chance = random(0, 11)
98 local alive = true
100 if chance == 0 then
101 alien_hut_get_gold(unit, 25)
102 elseif chance == 1 or chance == 2 or chance == 3 then
103 alien_hut_get_gold(unit, 50)
104 elseif chance == 4 then
105 alien_hut_get_gold(unit, 100)
106 elseif chance == 5 or chance == 6 or chance == 7 then
107 alien_hut_get_tech(unit)
108 elseif chance == 8 or chance == 9 then
109 alien_hut_get_gold(unit, 25)
110 elseif chance == 10 then
111 alive = alien_hut_get_barbarians(unit)
112 elseif chance == 11 then
113 if not alien_hut_get_city(unit) then
114 alien_hut_get_gold(unit, 50)
118 -- do not process default.lua
119 return true
122 signal.connect("hut_enter", "alien_hut_enter_callback")
124 -----------------------------------------------------------------------------------------------------
125 -- Alien ruleset specific callbacks
127 -- Show a pop up telling the beginning of the story when the game starts.
128 function turn_callback(turn, year)
129 if turn == 0 then
130 notify.event(nil, nil, E.SCRIPT,
131 _("Deneb 7 was known to have strange force field surrounding it\nthat made it impossible to get near planet with year\n250 Galactic Era Earth technology. However, when you were\nflying past, that field suddenly reverted and sucked you\nto the planet.\n\nYou find yourself in a strange world, probably touched\nby superior technology, where big portion of Earth science\nis invalid. You have to learn new rules,\nrules of this world.\n\nThere's deadly radiation that no known shielding works against.\nThere's alien life, but more surprisingly also some\nedible plants just like on Earth.\n\nRadio doesn't work,\nair doesn't allow flying, some basic Physics does\nnot apply here.\n\nYou struggle to live on this planet, and read\nRoadside Picnic by Strugatsky brothers once more."))
135 signal.connect('turn_started', 'turn_callback')