Re: Panzer Corps 2 - v1.02.02 Update
Posted: Thu Nov 25, 2021 6:06 pm
by nexusno2000
Moscow '41
Relevant parts of the script file below. The script format is LUA.
(basically it lays out 2 "spawn zones" which are a collection of hexes, and then there are 5 different waves to randomly pick from on each of turns 6,7,8,13,14,15,19,20)
---
normal_wave_turns = {6,7,8,13,14,15,19,20}
-- *** Hex zones ***
-- Spawn zones
-- When spawning a set of units, the script will scan spawn zones hex by hex, in the order specified, and spawn units in free hexes it finds
-- If the script runs out of hexes, the remainder of the units will not be spawned.
ru_spawn_zone1 = {{27,1},{29,1},{30,2},{31,2},{32,2},{30,3},{31,3},{32,3},{31,4},{32,4},{33,4},{31,5},{32,5},{33,5}}
ru_spawn_zone2 = {{34,10},{35,10},{34,11},{35,11},{35,12},{36,12},{35,13},{36,13},{35,14},{36,14},{34,15},{35,15},{36,15},{36,16},{37,16},{36,17}}
-- *** Enemy waves ***
-- Each unit set is a list of blocks in the following format: { "<Unit ID>", "<Transport ID>", overstrength, experience }
-- If no organic transport is needed, its respective field should be empty string ("").
-- Soviet waves
ru_wave1 = { {"Regular", "", 1, 900}, {"Regular", "", 1, 900}, {"SUHWInf", "SUTruck", 2, 900}, {"T34-41", "", 1, 900}, {"BT7", "", 2, 900}, {"122mmM1938", "SUTruck", 2, 900} }
ru_wave2 = { {"Regular", "", 1, 900}, {"Regular", "", 1, 900}, {"SUHWInf", "SUTruck", 2, 900}, {"T34-41", "", 1, 900}, {"BT7", "", 2, 900}, {"BM13Katyusha", "SUTruck", 2, 900} }
ru_wave3 = { {"Regular", "", 2, 900}, {"Regular", "", 2, 900}, {"SUHWInf", "SUTruck", 3, 900}, {"SUCavalry", "", 1, 900}, {"SUMntInf", "", 1, 900}, {"45mmM1937", "SUTruck", 2, 900}, {"BA10", "", 1, 900} }
ru_wave4 = { {"KV1-41", "", 1, 900}, {"T28", "", 1, 900}, {"T50", "", 2, 900}, {"T34-41", "", 1, 900}, {"BT7", "", 2, 900}, {"T34-41", "", 2, 900}, {"37mmM1939AA", "SUTruck", 2, 900}, {"122mmM1938", "SUTruck", 2, 900} }
ru_wave5 = { {"Regular", "", 1, 900}, {"BA10", "", 1, 900}, {"KV2TNK", "", 1, 900}, {"BT7A-ATY", "", 2, 900}, {"BM13Katyusha", "", 1, 900}, {"GazAAMG-AA", "", 2, 900}, {"Il2Shturmovik", "", 0, 900} }
-- There can be any number of waves in this list, the game will pick a random one every time
ru_waves = {ru_wave1, ru_wave2, ru_wave3, ru_wave4, ru_wave5}
-- There can be any number of zones in this list, the game will pick a random one every time
ru_zones = {ru_spawn_zone1, ru_spawn_zone2}
function SpawnWave(player, zone, units)
local owner = world:GetPlayer(player)
local cur_hex = 1
-- Iterate through all units and spawn each one
for _,u in ipairs(units) do
-- Find the next vacant hex in the zone
while zone[cur_hex] do
hex = world:GetHex(zone[cur_hex])
if hex:GetUnit(0) == nil then break end -- found
cur_hex = cur_hex + 1
end
-- If we have run out of hexes in the zone, stop
if not zone[cur_hex] then return end
-- Create the unit in the free hex we've found
-- 1. Create and execute purchase action, use unit type, transport type and overstrength as parameters
local create_action = world:MakePurchaseAction(owner, u[1], u[2], u[3])
create_action.auxiliary = false -- spawn core units
create_action.cost = 0 -- don't take money for units we generate
create_action.faction = owner.factions[1] --set to first faction of owning player for created units
world:Exec(create_action)
-- 2. Create and execute deploy action, place the unit in the hex we've picked.
local unit = world:GetUnit(create_action.id)
deploy_action = world:MakeDeployAction(unit, zone[cur_hex])
world:Exec(deploy_action)
-- 3. Now modify the unit to set its experience to the value we need.
unit.experience = u[4]
-- 4. Now modify the unit to set its aggressiveness to the value we need.
player_aggressiveness = { 0, 85, 70, 70 }
unit.aggressiveness = player_aggressiveness[player+1]
end
end
function OnNewRound(action)
-- On the first call, initialize the random generator
if world.round == 1 then
math.randomseed(world.seed)
end
-- Do we need to spawn a normal wave?
local is_normal_wave = IsItemInTable(normal_wave_turns, world.round)
-- Do we need to spawn a boss wave?
--local boss_wave = FindItemInTable(boss_wave_turns, world.round) -- boss wave number
--local is_boss_wave = (boss_wave ~= -1)
-- If we don't need to spawn any normal or boss waves this turn then just finish
if not is_normal_wave then return end
-- Determine the player to get the next wave, always USSR 2 Siberians
player = 2
-- Determine the right zone and units to spawn
local zone
local units
-- Player 1 is USSR
zone = ru_zones[ math.random( #ru_zones ) ] -- random normal ru zone
units = ru_waves[ math.random( #ru_waves ) ] -- random normal ru wave
-- Now spawn this wave!
SpawnWave(player, zone, units)
end
-- *** Utility functions ***
function FindItemInTable(table, item)
for index,i in ipairs(table) do
if i == item then
return index
end
end
return -1
end
function IsItemInTable(table, item)
return FindItemInTable(table, item) ~= -1
end
function EmptyCondition()
return true
end