25 HedgewarsScriptLoad("/Scripts/Tracker.lua") |
25 HedgewarsScriptLoad("/Scripts/Tracker.lua") |
26 |
26 |
27 local weapons = {} |
27 local weapons = {} |
28 local weapons_values = {} |
28 local weapons_values = {} |
29 local weapons_count = 0 |
29 local weapons_count = 0 |
30 local airweapons = {} |
|
31 local airweapons_values = {} |
|
32 local utilities = {} |
30 local utilities = {} |
33 local utilities_values = {} |
31 local utilities_values = {} |
|
32 local utilities_count = 0 |
|
33 |
|
34 local gotten_air_weapons = {} |
34 |
35 |
35 local isUtility, isAirWeapon |
36 local isUtility, isAirWeapon |
36 |
37 |
37 function randomAmmo() |
38 function randomAmmo() |
38 --[[ |
39 --[[ |
52 e. Randomly add one of the items which are still in mind to the hedgehog's ammo and substract cost |
53 e. Randomly add one of the items which are still in mind to the hedgehog's ammo and substract cost |
53 f. Return to step 2 |
54 f. Return to step 2 |
54 |
55 |
55 If 0 points are left, the algorithm terminates. |
56 If 0 points are left, the algorithm terminates. |
56 ]] |
57 ]] |
|
58 local picked_items = {} |
57 |
59 |
58 local n = 3 --"points" to be allocated on weapons |
60 local n = 3 --"points" to be allocated on weapons |
59 |
61 |
60 --pick random weapon and subtract cost |
62 --pick random weapon and subtract cost |
61 local r = GetRandom(weapons_count) + 1 |
63 if weapons_count > 0 then |
62 local picked_items = {} |
64 local r = GetRandom(weapons_count) + 1 |
63 table.insert(picked_items, weapons[r]) |
65 table.insert(picked_items, weapons[r]) |
64 n = n - weapons_values[r] |
66 n = n - weapons_values[r] |
65 |
67 elseif utilities_count > 0 then |
|
68 local r = GetRandom(utilities_count) + 1 |
|
69 table.insert(picked_items, utilities[r]) |
|
70 n = n - utilities_values[r] |
|
71 else |
|
72 return picked_items |
|
73 end |
66 |
74 |
67 --choose any weapons or utilities to use up remaining n |
75 --choose any weapons or utilities to use up remaining n |
68 |
76 |
69 while n > 0 do |
77 while n > 0 do |
70 local items = {} |
78 local items = {} |
191 end |
199 end |
192 end |
200 end |
193 |
201 |
194 function onGameStart() |
202 function onGameStart() |
195 trackTeams() |
203 trackTeams() |
|
204 -- Add air weapons |
196 if MapHasBorder() == false then |
205 if MapHasBorder() == false then |
197 for a = 0, AmmoTypeMax do |
206 for a = 0, AmmoTypeMax do |
198 if a ~= amNothing and a ~= amSkip then |
207 if isAirWeapon[a] then |
199 local ammoCount = GetAmmo(a) |
208 local gotten = gotten_air_weapons[a] |
|
209 local ammoCount, prob, delay, ammoInCrate = gotten[1], gotten[2], gotten[3], gotten[4] |
200 local cost = getCost(a, ammoCount) |
210 local cost = getCost(a, ammoCount) |
201 if cost > 0 and isAirWeapon[a] then |
211 if cost > 0 then |
202 table.insert(airweapons, a) |
212 table.insert(weapons, a) |
203 table.insert(airweapons_values, cost) |
213 table.insert(weapons_values, cost) |
|
214 weapons_count = weapons_count + 1 |
204 end |
215 end |
205 end |
216 end |
206 end |
217 end |
207 end |
218 end |
208 end |
219 end |
211 SetAmmo(amSkip, 9, 0, 0, 0) |
222 SetAmmo(amSkip, 9, 0, 0, 0) |
212 |
223 |
213 for a=0, AmmoTypeMax do |
224 for a=0, AmmoTypeMax do |
214 if a ~= amNothing and a ~= amSkip then |
225 if a ~= amNothing and a ~= amSkip then |
215 local ammoCount, prob, delay, ammoInCrate = GetAmmo(a) |
226 local ammoCount, prob, delay, ammoInCrate = GetAmmo(a) |
216 local cost = getCost(a, ammoCount) |
|
217 if (not isAirWeapon[a]) then |
227 if (not isAirWeapon[a]) then |
|
228 local cost = getCost(a, ammoCount) |
218 if cost > 0 then |
229 if cost > 0 then |
219 if isUtility[a] then |
230 if isUtility[a] then |
220 table.insert(utilities, a) |
231 table.insert(utilities, a) |
221 table.insert(utilities, cost) |
232 table.insert(utilities_values, cost) |
|
233 utilities_count = utilities_count + 1 |
222 else |
234 else |
223 table.insert(weapons, a) |
235 table.insert(weapons, a) |
224 table.insert(weapons_values, cost) |
236 table.insert(weapons_values, cost) |
225 weapons_count = weapons_count + 1 |
237 weapons_count = weapons_count + 1 |
226 end |
238 end |
227 end |
239 end |
228 else |
240 else |
229 prob = 0 |
241 -- air weapons are handled in onGameStart |
|
242 gotten_air_weapons[a] = { ammoCount, prob, delay, ammoInCrate } |
230 end |
243 end |
231 local realAmmoCount |
244 local realAmmoCount |
232 if ammoCount ~= 9 then |
245 if ammoCount ~= 9 then |
233 realAmmoCount = 0 |
246 realAmmoCount = 0 |
234 else |
247 else |