- Joined
- Jul 18, 2010
- Messages
- 2,377
The reason i reclac the starting positions is, I change the teams inside a map Init Trigger, which should load after the placing. So the starting locations would be quite random and teams are complettly splited in most times.
Therefore I wrote that Jass Script changing the used starting positions for all Players, placing Teams together. Often it produces good results, but othertimes one team is placed completly unfair.
Like in this pictures:

Team Teal isn't placed together.
or in that one:

Team Purple is not placed Together.
I also tested the maps with the default Blizzard Team-placement (1.30) which also produces this situtations.
Or does it not matter at all and that error is just who cares?
Therefore I wrote that Jass Script changing the used starting positions for all Players, placing Teams together. Often it produces good results, but othertimes one team is placed completly unfair.
Like in this pictures:

Team Teal isn't placed together.
or in that one:

Team Purple is not placed Together.
I also tested the maps with the default Blizzard Team-placement (1.30) which also produces this situtations.
The question would be how would one avoid such situation or if that would be to costly how would one detect such a situation in most cases/maps and just redo the whole starting position.
Or does it not matter at all and that error is just who cares?
JASS:
function CalcStartingLocs takes nothing returns nothing
local integer LoopAlly = 0
local integer LoopPrim = 0
local integer LoopLoc = 0
local force isPlaced = CreateForce()
local integer array startLocations
local integer startLocationsLast = -1
local integer random
local real distance
local real dx
local real dy
local real newDistance
local integer neareastLocIndex
loop
exitwhen LoopPrim == GetPlayers()
set startLocations[LoopPrim] = LoopPrim
set startLocationsLast = startLocationsLast + 1
set LoopPrim = LoopPrim + 1
endloop
set LoopPrim = 0
loop
exitwhen LoopPrim == GetPlayers()
if IsPlayerInForce(Player(LoopPrim), bj_FORCE_ALL_PLAYERS) then //Valid Player
if not IsPlayerInForce(Player(LoopPrim), isPlaced) then // not placed yet
set random = GetRandomInt(0, startLocationsLast)
call SetPlayerStartLocation(Player(LoopPrim), startLocations[random])
set startLocations[random] = startLocations[startLocationsLast]
set startLocationsLast = startLocationsLast - 1
call ForceAddPlayer(isPlaced, Player(LoopPrim))
set LoopAlly = LoopPrim + 1
//Loop Further Players
//Find allies and give them a nearby Location.
loop
exitwhen LoopAlly == GetPlayers()
if IsPlayerInForce(Player(LoopPrim), bj_FORCE_ALL_PLAYERS) then //Valid Player
if IsPlayerAlly(Player(LoopPrim), Player(LoopAlly)) and not IsPlayerInForce(Player(LoopAlly), isPlaced) then
set LoopLoc = 0
set distance = 9999999
set neareastLocIndex = -1
loop // Find nearest
exitwhen LoopLoc > startLocationsLast
//check nearer
set dx = GetStartLocationX(startLocations[LoopLoc]) - GetStartLocationX(GetPlayerStartLocation(Player(LoopPrim)))
set dy = GetStartLocationY(startLocations[LoopLoc]) - GetStartLocationY(GetPlayerStartLocation(Player(LoopPrim)))
set newDistance = SquareRoot(dx * dx + dy * dy)
if newDistance < distance then
set distance = newDistance
set neareastLocIndex = LoopLoc
endif
set LoopLoc = LoopLoc + 1
endloop
call SetPlayerStartLocation(Player(LoopAlly), startLocations[neareastLocIndex])
set startLocations[neareastLocIndex] = startLocations[startLocationsLast]
set startLocationsLast = startLocationsLast - 1
call ForceAddPlayer(isPlaced, Player(LoopAlly))
endif
endif
set LoopAlly = LoopAlly + 1
endloop
endif
endif
set LoopPrim = LoopPrim + 1
endloop
call DestroyForce(isPlaced)
set isPlaced = null
endfunction