wormDelay = nil
testCondition = true
WorldLoaded = function()
  --get players
	mp0=Player.GetPlayer("Multi0")
	mp1=Player.GetPlayer("Multi1")
	mp2=Player.GetPlayer("Multi2")
	mp3=Player.GetPlayer("Multi3")
	mp4=Player.GetPlayer("Multi4")
	mp5=Player.GetPlayer("Multi5")
	mp6=Player.GetPlayer("Multi6")
	mp7=Player.GetPlayer("Multi7")
	mp8=Player.GetPlayer("Multi8")
	mp9=Player.GetPlayer("Multi9")
	mp10=Player.GetPlayer("Multi10")
	mp11=Player.GetPlayer("Multi11")
	mp12=Player.GetPlayer("Multi12")
	mp13=Player.GetPlayer("Multi13")
  players = {mp0, mp1, mp2, mp3, mp4, mp5, mp6, mp7, mp8, mp9, mp10, mp11, mp12, mp13}
  -- freecarryall section
  for i, player in pairs(players)
  do
    if player.HasPrerequisites({"FreeCarry"})
    then
      addCarryToPlayer(player)
    end
  end  
  -- worm delay section
  wormDelay = Map.LobbyOption("WormsSpawnDelay")
  if tonumber(wormDelay) > 0
  then
    delay = tonumber(Map.LobbyOption("WormsSpawnDelay"))
    Trigger.AfterDelay(DateTime.Minutes(delay), function()
        wormSpawnFunction()  
     end)
  else
    wormSpawnFunction()
  end

end


function addCarryToPlayer(player)
  local actors = player.GetActorsByType("mcv")
  local hasCarry = false
  for i, actor in pairs(actors)
  do
    if (actor.Type == "mcv") or (actor.Type == "construction_yard")
    then
      if (not hasCarry )
      then
        Reinforcements.Reinforce(player, { "carryall" }, { actor.Location }, 10)
        hasCarry = true
      end
    end
  end
end

function wormSpawnFunction()
    creepPlayer = Player.GetPlayer("Creeps")
    actorsSpawner = creepPlayer.GetActorsByType("wormspawner")
  if actorsSpawner ~= nil
  then
    for i, spawner in pairs(actorsSpawner)
    do
      if spawner.AcceptsCondition("WormSpamDelayed")
      then
        spawner.GrantCondition("WormSpamDelayed") 	
      end
    end
  end
end


