author | unc0rr |
Sat, 24 Aug 2013 01:37:20 +0400 | |
branch | 0.9.19 |
changeset 9142 | 0dceffbaa4ee |
parent 9138 | 9e94a9bc8c7e |
child 9657 | 2d8cae3c0855 |
permissions | -rw-r--r-- |
4506
37744d5c877e
Finnished up the lua translations by adding training maps, campaign is ignored for now
Henek
parents:
4503
diff
changeset
|
1 |
-- Hedgewars - Roperace for 2+ Players |
4188 | 2 |
|
9093 | 3 |
HedgewarsScriptLoad("/Scripts/Locale.lua") |
4188 | 4 |
|
5 |
-- store number of hedgehogs |
|
6 |
local numhhs = 0 |
|
7 |
||
8 |
-- store hedgehog gears |
|
9 |
local hhs = {} |
|
10 |
||
11 |
-- store best time per team |
|
12 |
local clantimes = {} |
|
13 |
||
14 |
-- store best times |
|
15 |
local times = {} |
|
16 |
||
17 |
-- in milisseconds |
|
18 |
local maxtime = 99000 |
|
19 |
||
20 |
-- define start area (left, top, width, height) |
|
21 |
local start_area = {1606, 498, 356, 80} |
|
22 |
||
23 |
-- define goal area (left, top, width, height) |
|
24 |
local goal_area = {2030, 300, 56, 280} |
|
25 |
||
26 |
-- last active hog |
|
27 |
local lasthog = nil |
|
28 |
||
29 |
-- active hog reached the goal? |
|
30 |
local reached = false |
|
31 |
||
32 |
-- hog with best time |
|
33 |
local besthog = nil |
|
9142
0dceffbaa4ee
Fix script flaw in detection of best team when sending achievement info
unc0rr
parents:
9138
diff
changeset
|
34 |
local besthogteam = "" |
4188 | 35 |
|
36 |
-- hog with worst time (per round) |
|
37 |
local worsthog = nil |
|
38 |
||
39 |
-- best time |
|
40 |
local besttime = maxtime + 1 |
|
41 |
||
42 |
-- worst time (per round) |
|
43 |
local worsttime = 0 |
|
44 |
||
45 |
function onGameInit() |
|
46 |
GameFlags = gfSolidLand + gfInvulnerable |
|
47 |
TurnTime = maxtime |
|
48 |
CaseFreq = 0 |
|
49 |
MinesNum = 0 |
|
50 |
Explosives = 0 |
|
51 |
Delay = 500 |
|
52 |
SuddenDeathTurns = 99999 -- "disable" sudden death |
|
53 |
Theme = 'Olympics' |
|
54 |
end |
|
55 |
||
56 |
function onGameStart() |
|
4503 | 57 |
ShowMission(loc("TrophyRace"), "", loc("Use your rope to get from start to finish as fast as you can!"), -amRope, 0) |
4188 | 58 |
started = true |
59 |
p=1820 |
|
60 |
for i = 0, numhhs - 1 do |
|
61 |
p = p + 50 |
|
62 |
SetGearPosition(hhs[i], p, 0) |
|
63 |
end |
|
64 |
||
65 |
for i=0, ClansCount-1 do |
|
66 |
clantimes[i] = 0 |
|
67 |
end |
|
68 |
end |
|
69 |
||
70 |
function onAmmoStoreInit() |
|
71 |
SetAmmo(amRope, 9, 2, 0) |
|
72 |
end |
|
73 |
||
7771 | 74 |
function onGameTick20() |
75 |
if CurrentHedgehog ~= nil and TurnTimeLeft <= 20 and TurnTimeLeft > 0 then |
|
4188 | 76 |
SetHealth(CurrentHedgehog, 0) |
77 |
x, y = GetGearPosition(CurrentHedgehog) |
|
7771 | 78 |
AddGear(x, y, gtShell, 0, 0, 0, 0) |
4188 | 79 |
worsttime = 99999 |
80 |
worsthog = nil |
|
7771 | 81 |
elseif TurnTimeLeft > maxtime - 25 and CurrentHedgehog ~= nil then |
4188 | 82 |
if lasthog ~= nil then |
83 |
SetGearPosition(lasthog, p , 0) |
|
84 |
end |
|
85 |
reached = false |
|
7771 | 86 |
SetGearVelocity(CurrentHedgehog, 1, 0) |
4188 | 87 |
SetGearPosition(CurrentHedgehog, start_area[1] + start_area[3] / 2, start_area[2] + start_area[4] / 2) |
7771 | 88 |
ParseCommand("setweap " .. string.char(amRope)) |
89 |
lasthog = CurrentHedgehog |
|
4188 | 90 |
elseif CurrentHedgehog ~= nil then |
91 |
x, y = GetGearPosition(CurrentHedgehog) |
|
92 |
if not reached and x > goal_area[1] and x < goal_area[1] + goal_area[3] and y > goal_area[2] and y < goal_area[2] + goal_area[4] then -- hog is within goal rectangle |
|
93 |
reached = true |
|
94 |
local ttime = maxtime - TurnTimeLeft |
|
95 |
--give it a sound;) |
|
96 |
if ttime < besttime then |
|
97 |
PlaySound (sndHomerun) |
|
98 |
else |
|
99 |
PlaySound (sndHellish) |
|
100 |
end |
|
101 |
for i = 0, numhhs - 1 do |
|
102 |
if hhs[i] == CurrentHedgehog then |
|
103 |
times[numhhs] = ttime |
|
104 |
end |
|
105 |
end |
|
106 |
||
107 |
local hscore = "| |" |
|
108 |
local clan = GetHogClan(CurrentHedgehog) |
|
109 |
if ttime < clantimes[clan] or clantimes[clan] == 0 then |
|
110 |
clantimes[clan] = ttime |
|
111 |
end |
|
112 |
||
113 |
if ttime < besttime then |
|
114 |
besttime = ttime |
|
115 |
besthog = CurrentHedgehog |
|
9142
0dceffbaa4ee
Fix script flaw in detection of best team when sending achievement info
unc0rr
parents:
9138
diff
changeset
|
116 |
besthogteam = GetHogTeamName(besthog) |
4503 | 117 |
hscore = hscore .. loc("NEW fastest lap: ") |
4188 | 118 |
else |
4503 | 119 |
hscore = hscore .. loc("Fastest lap: ") |
4188 | 120 |
end |
121 |
if ttime > worsttime then |
|
122 |
worsttime = ttime |
|
123 |
worsthog = CurrentHedgehog |
|
124 |
end |
|
4503 | 125 |
hscore = hscore .. GetHogName(besthog) .. " - " .. (besttime / 1000) .. " s | |" .. loc("Best laps per team: ") |
4188 | 126 |
|
127 |
if clan == ClansCount -1 then |
|
128 |
-- Time for elimination - worst hog is out and the worst hog vars are reset. |
|
129 |
SetHealth(worsthog, 0) |
|
130 |
--Place a grenade to make inactive slowest hog active |
|
131 |
x, y = GetGearPosition(worsthog) |
|
132 |
AddGear(x, y, gtShell, 0, 0, 0, 0) |
|
133 |
worsttime = 0 |
|
134 |
worsthog = nil |
|
135 |
end |
|
136 |
||
137 |
for i=0, ClansCount -1 do |
|
138 |
local tt = "" .. (clantimes[i] / 1000) .. " s" |
|
139 |
if clantimes[i] == 0 then |
|
140 |
tt = "--" |
|
141 |
end |
|
4503 | 142 |
hscore = hscore .. "|" .. string.format(loc("Team %d: "), i+1) .. tt |
4188 | 143 |
end |
144 |
||
4503 | 145 |
ShowMission(loc("TrophyRace"), "", loc("You've reached the goal!| |Time: ") .. (ttime / 1000) .. " s" .. hscore, 0, 0) |
4188 | 146 |
TurnTimeLeft = 0 |
147 |
end |
|
148 |
end |
|
149 |
end |
|
150 |
||
151 |
function onGearAdd(gear) |
|
152 |
if GetGearType(gear) == gtHedgehog then |
|
153 |
hhs[numhhs] = gear |
|
154 |
times[numhhs] = 0 |
|
155 |
numhhs = numhhs + 1 |
|
156 |
end |
|
7771 | 157 |
-- elseif GetGearType(gear) == gtRope then -- rope is shot |
4188 | 158 |
end |
159 |
||
7771 | 160 |
--function onGearDelete(gear) |
161 |
-- if GetGearType(gear) == gtRope then -- rope deletion - hog didn't manage to rerope |
|
162 |
-- --TurnTimeLeft = 0 -- end turn or not? hm... |
|
163 |
-- lasthog = CurrentHedgehog |
|
164 |
-- |
|
165 |
-- end |
|
166 |
--end |
|
9135 | 167 |
|
168 |
function onAchievementsDeclaration() |
|
169 |
if besthog ~= nil then |
|
9142
0dceffbaa4ee
Fix script flaw in detection of best team when sending achievement info
unc0rr
parents:
9138
diff
changeset
|
170 |
DeclareAchievement("rope race", besthogteam, "TrophyRace", besttime) |
9135 | 171 |
end |
172 |
end |