author | nemo |
Sat, 22 Dec 2012 21:04:47 -0500 | |
changeset 8319 | 408371c03140 |
parent 7771 | ce6d4dd0c780 |
child 8349 | a1dbe148f10f |
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 |
|
4506
37744d5c877e
Finnished up the lua translations by adding training maps, campaign is ignored for now
Henek
parents:
4503
diff
changeset
|
3 |
loadfile(GetDataPath() .. "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 |
|
34 |
||
35 |
-- hog with worst time (per round) |
|
36 |
local worsthog = nil |
|
37 |
||
38 |
-- best time |
|
39 |
local besttime = maxtime + 1 |
|
40 |
||
41 |
-- worst time (per round) |
|
42 |
local worsttime = 0 |
|
43 |
||
44 |
function onGameInit() |
|
45 |
GameFlags = gfSolidLand + gfInvulnerable |
|
46 |
TurnTime = maxtime |
|
47 |
CaseFreq = 0 |
|
48 |
MinesNum = 0 |
|
49 |
Explosives = 0 |
|
50 |
Delay = 500 |
|
51 |
SuddenDeathTurns = 99999 -- "disable" sudden death |
|
52 |
Theme = 'Olympics' |
|
53 |
end |
|
54 |
||
55 |
function onGameStart() |
|
4503 | 56 |
ShowMission(loc("TrophyRace"), "", loc("Use your rope to get from start to finish as fast as you can!"), -amRope, 0) |
4188 | 57 |
started = true |
58 |
p=1820 |
|
59 |
for i = 0, numhhs - 1 do |
|
60 |
p = p + 50 |
|
61 |
SetGearPosition(hhs[i], p, 0) |
|
62 |
end |
|
63 |
||
64 |
for i=0, ClansCount-1 do |
|
65 |
clantimes[i] = 0 |
|
66 |
end |
|
67 |
end |
|
68 |
||
69 |
function onAmmoStoreInit() |
|
70 |
SetAmmo(amRope, 9, 2, 0) |
|
71 |
end |
|
72 |
||
7771 | 73 |
function onGameTick20() |
74 |
if CurrentHedgehog ~= nil and TurnTimeLeft <= 20 and TurnTimeLeft > 0 then |
|
4188 | 75 |
SetHealth(CurrentHedgehog, 0) |
76 |
x, y = GetGearPosition(CurrentHedgehog) |
|
7771 | 77 |
AddGear(x, y, gtShell, 0, 0, 0, 0) |
4188 | 78 |
worsttime = 99999 |
79 |
worsthog = nil |
|
7771 | 80 |
elseif TurnTimeLeft > maxtime - 25 and CurrentHedgehog ~= nil then |
4188 | 81 |
if lasthog ~= nil then |
82 |
SetGearPosition(lasthog, p , 0) |
|
83 |
end |
|
84 |
reached = false |
|
7771 | 85 |
SetGearVelocity(CurrentHedgehog, 1, 0) |
4188 | 86 |
SetGearPosition(CurrentHedgehog, start_area[1] + start_area[3] / 2, start_area[2] + start_area[4] / 2) |
7771 | 87 |
ParseCommand("setweap " .. string.char(amRope)) |
88 |
lasthog = CurrentHedgehog |
|
4188 | 89 |
elseif CurrentHedgehog ~= nil then |
90 |
x, y = GetGearPosition(CurrentHedgehog) |
|
91 |
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 |
|
92 |
reached = true |
|
93 |
local ttime = maxtime - TurnTimeLeft |
|
94 |
--give it a sound;) |
|
95 |
if ttime < besttime then |
|
96 |
PlaySound (sndHomerun) |
|
97 |
else |
|
98 |
PlaySound (sndHellish) |
|
99 |
end |
|
100 |
for i = 0, numhhs - 1 do |
|
101 |
if hhs[i] == CurrentHedgehog then |
|
102 |
times[numhhs] = ttime |
|
103 |
end |
|
104 |
end |
|
105 |
||
106 |
local hscore = "| |" |
|
107 |
local clan = GetHogClan(CurrentHedgehog) |
|
108 |
if ttime < clantimes[clan] or clantimes[clan] == 0 then |
|
109 |
clantimes[clan] = ttime |
|
110 |
end |
|
111 |
||
112 |
if ttime < besttime then |
|
113 |
besttime = ttime |
|
114 |
besthog = CurrentHedgehog |
|
4503 | 115 |
hscore = hscore .. loc("NEW fastest lap: ") |
4188 | 116 |
else |
4503 | 117 |
hscore = hscore .. loc("Fastest lap: ") |
4188 | 118 |
end |
119 |
if ttime > worsttime then |
|
120 |
worsttime = ttime |
|
121 |
worsthog = CurrentHedgehog |
|
122 |
end |
|
4503 | 123 |
hscore = hscore .. GetHogName(besthog) .. " - " .. (besttime / 1000) .. " s | |" .. loc("Best laps per team: ") |
4188 | 124 |
|
125 |
if clan == ClansCount -1 then |
|
126 |
-- Time for elimination - worst hog is out and the worst hog vars are reset. |
|
127 |
SetHealth(worsthog, 0) |
|
128 |
--Place a grenade to make inactive slowest hog active |
|
129 |
x, y = GetGearPosition(worsthog) |
|
130 |
AddGear(x, y, gtShell, 0, 0, 0, 0) |
|
131 |
worsttime = 0 |
|
132 |
worsthog = nil |
|
133 |
end |
|
134 |
||
135 |
for i=0, ClansCount -1 do |
|
136 |
local tt = "" .. (clantimes[i] / 1000) .. " s" |
|
137 |
if clantimes[i] == 0 then |
|
138 |
tt = "--" |
|
139 |
end |
|
4503 | 140 |
hscore = hscore .. "|" .. string.format(loc("Team %d: "), i+1) .. tt |
4188 | 141 |
end |
142 |
||
4503 | 143 |
ShowMission(loc("TrophyRace"), "", loc("You've reached the goal!| |Time: ") .. (ttime / 1000) .. " s" .. hscore, 0, 0) |
4188 | 144 |
TurnTimeLeft = 0 |
145 |
end |
|
146 |
end |
|
147 |
end |
|
148 |
||
149 |
function onGearAdd(gear) |
|
150 |
if GetGearType(gear) == gtHedgehog then |
|
151 |
hhs[numhhs] = gear |
|
152 |
times[numhhs] = 0 |
|
153 |
numhhs = numhhs + 1 |
|
154 |
end |
|
7771 | 155 |
-- elseif GetGearType(gear) == gtRope then -- rope is shot |
4188 | 156 |
end |
157 |
||
7771 | 158 |
--function onGearDelete(gear) |
159 |
-- if GetGearType(gear) == gtRope then -- rope deletion - hog didn't manage to rerope |
|
160 |
-- --TurnTimeLeft = 0 -- end turn or not? hm... |
|
161 |
-- lasthog = CurrentHedgehog |
|
162 |
-- |
|
163 |
-- end |
|
164 |
--end |