GameRulesName = "WARLORDS 0.45" Description = "Game rules for SW:WARLORDS" Directories = { Levels = "data:LevelData\\Multiplayer\\Deathmatch\\", ProfileLevels = "profiles:Levels\\Deathmatch\\", } GUID = {218, 133, 165, 204, 182, 239, 184, 193, 157, 20, 231, 124, 48, 169, 31, 97} GameSetupOptions = { -- set starting fleet { name = "startwith", locName = "starting fleet", tooltip = "sets starting fleet", default = 1, visible = 1, choices = { "Facilties", "mothership", "Reinforcements", "Rein", "Construction", "Construction", "Defense", "Defense", -- "Endor", "Endor", "none", "none", }, }, -- allow player to select what era they are in or select limited building { name = "BuildRestrict", locName = "Build Restriction", tooltip = "Restriction based on era or other limits", default = 0, visible = 1, choices = { "Unlimited", "FUNLIMITED", "No build", "NOBUILD", "Limited", "LIMITED", "Clone Wars", "CLONEWARS", "ANH", "ANH", "HOTH", "HOTH", "ROTJ", "ROTJ", "POST ROTJ", "PROTJ", "Dark Empire", "DE", "Pre-NJO", "PNJO", "NJO", "NJO", }, }, --allow player to select the maximum size of ship that they can build { name = "MaxShip", locName = "Class Restriction", tooltip = "Restriction based on ship size", default = 0, visible = 1, choices = { "Unlimited", "UNLIMITED", "< Super caps", "SUPERCAP", "< Cruisers", "CRUISER", "< Destroyers", "DESTROYER", "< Heavy Frigate", "HEAVYFRIGATE", }, }, --set unit cap selections { name = "unitcaps", locName = "Unit cap", tooltip = "set the unit cap", default = 1, visible = 1, choices = { "Small", "Small", "Normal", "Normal", "Large", "Large", "Capitals", "Capitals", "Strike Group", "strikegroup", "Taskforce", "taskforce", "Strike Group No F", "strikegroupnofighter", "Unlimited", "Unlimited", }, }, -- starting resource option { name = "resstart", locName = "starting RU's", tooltip = "set starting Ru's here", default = 4, visible = 1, choices = { "2000", "2000", "5000", "5000", "10000", "10000", "20000", "20000", "50000", "50000", "100000", "100000", "500000", "500000", "1000000", "1000000", "2000000", "2000000", "none", "1", --resourcing disabled }, }, --set win condition { name = "wincondition", locName = "win condition", tooltip = "sets game win conditions", default = 2, visible = 1, choices = { "Destroy Production", "DestroyProduction", "Capture Capital", "CaptureCapital", "Destroy All", "DestroyAll", }, }, { name = "Research_Enable", locName = "Research", tooltip = "Enables or Disables Research Requirements", default = 1, visible = 1, choices = { "Enabled", "1", "Disabled", "0", }, }, { name = "resenable", locName = "Resourcing Enabled", tooltip = "Enables or Disables Resourcing", default = 0, visible = 1, choices = { "Enabled", "1", "Disabled", "0", }, }, -- lock team option { name = "lockteams", locName = "Lock teams", tooltip = "prevent team switching", default = 1, visible = 1, choices = { "yes", "yes", "no", "no", }, }, -- start location option { name = "startlocation", locName = "start location", tooltip = "set start location", default = 1, visible = 1, choices = { "random", "random", "fixed", "fixed", }, }, { name = "resources", locName = "resource multiplier", tooltip = "multiply resources by this amount", default = 3, visible = 1, choices = { "0.1", "0.1", "0.25", "0.25", "0.5", "0.5", "1.0", "1.0", "2.0", "2.0", "0.0", "0.0", }, }, --resource injection amounts { name = "resourceinjection", locName = "RU injection", tooltip = "RU injection amount", default = 0, visible = 1, choices = { "0", "0", "500", "500", "1000", "1000", "2000", "2000", "5000", "5000", "10000", "10000", "25000", "25000", "50000", "50000", "100000", "100000", }, }, --injection timing { name = "resourceinjectionevery", locName = "injection rate", tooltip = "RU injection rate", default = 0, visible = 1, choices = { "10 sec", "10", "30 sec", "30", "1 min", "60", "2 min", "120", "5 min", "300", "10 min", "600", "20 min", "1200", }, }, --lump sum injection { name = "resourcelumpsum", locName = "RU lump sum", tooltip = "One time injection amount", default = 0, visible = 1, choices = { "off", "off", "10000", "10000", "20000", "20000", "50000", "50000", "100000", "100000", "200000", "200000", "500000", "500000", "1000000", "1000000", "2000000", "2000000", }, }, --lump sum delay { name = "resourcelumpsumafter", locName = "Lump sum delay", tooltip = "delay for lump sum", default = 0, visible = 1, choices = { "2 min", "120", "5 min", "300", "10 min", "600", "20 min", "1200", "40 min", "2400", }, }, { name = "Play_Rnd_Music", locName = "Random Music", tooltip = "Play Random Music", default = 1, visible = 1, choices = { "Yes", "1", "No", "0", }, }, } dofilepath("data:scripts/scar/restrict.lua") dofilepath("data:scripts/scar/restrict_list.lua") dofilepath("data:scripts/scar/scar_util.lua") capturePlayerIndex = 0 destroyResourcerIndex = 0 --disableHyperspaceIndex = 0 --for disabling HS, just put an uber grav well thing in --add support for ghost viewers --privateer mode turns on bounties and turns off resourcing? PrintfCharacters = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"} ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- --Game Entry Point ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- function OnInit() era = GetGameSettingAsString("BuildRestrict") tonnage = GetGameSettingAsString("MaxShip") print("RUN MP RESTRICT") MPRestrict(); -- setup a random seed if (GetGameSettingAsNumber("Research_Enable") == 0) then print("ENABLE ALL RESEARCH") Rule_Add("GrantResearchRule") end print("BUILD LIMIT RULE") Rule_Add("buildlimitRule") -- add this rule Rule_Add("MainRule") print("GAMETYPES=====================================") print("INJECTIONS=====================================") -- setup resource injections local resourceInjectionAmount = GetGameSettingAsNumber("resourceinjection") if (resourceInjectionAmount > 0) then local resourceInjectionTime = GetGameSettingAsNumber("resourceinjectionevery") print("Resource injections of "..resourceInjectionAmount.." every "..resourceInjectionTime.."seconds") Rule_AddInterval("ResourceInjectionRule", resourceInjectionTime) end --setup lump sum resource injection local resourceLumpSumAmount = GetGameSettingAsNumber("resourcelumpsum") if (resourceLumpSumAmount > 0) then local resourceLumpSumTime = GetGameSettingAsNumber("resourcelumpsumafter") print("Resource injections of "..resourceLumpSumAmount.." every "..resourceLumpSumTime.."seconds") Rule_AddInterval("ResourceLumpSumRule", resourceLumpSumTime) end print("WIN CONDITIONS================================") local winCondition = GetGameSettingAsString("wincondition"); --setup the destroy mothership rule if (winCondition == "DestroyProduction") then print("Destroy Production win condition enabled") Rule_AddInterval("CheckMothershipDeadRule", 1) elseif (winCondition == "DestroyAll") then print("Destroy All win condition enabled") Rule_AddInterval("CheckDeadRule", 1) elseif (winCondition == "CaptureCapital") then print("Capture cap ship win condition enabled") local playerIndex = 0 local playerCount = Universe_PlayerCount(); while (playerIndex < playerCount) do local groupName = "captureGroup_"..playerIndex SobGroup_Create(groupName) SobGroup_SetSwitchOwnerFlag(groupName, 0) playerIndex = playerIndex+1 end capturePlayerIndex = 0 Rule_AddInterval("CheckCaptureStatusRule", 1) end --setup the "Resourceing Disabled Option" if (GetGameSettingAsString("resenable") == "0") then print("Resourcing disabled") destroyResourcerIndex = 0 SobGroup_Create("ResourcersToDestroy") Rule_AddInterval("DestroyResourcersRule", 1.23) local playerIndex = 0 local playerCount = Universe_PlayerCount(); while (playerIndex < playerCount) do Resourcer_Kill(playerIndex) --Player_SetRU(playerIndex, 0) playerIndex = playerIndex+1 end end print("STARTING FLEETS=========================================") --setup the "carrier battle": start with a different fleet if (GetGameSettingAsString("startwith") == "mothership") then print("Setting up MotherShip battle") SetStartFleetSuffix("") elseif (GetGameSettingAsString("startwith") == "carrier") then print("Setting up carrier battle") SetStartFleetSuffix("Carrier") elseif (GetGameSettingAsString("startwith") == "Endor") then print("Setting up Endor battle") SetStartFleetSuffix("Endor") elseif (GetGameSettingAsString("startwith") == "Rein") then print("Setting up Reinforcements battle") SetStartFleetSuffix("Rein") elseif (GetGameSettingAsString("startwith") == "Defense") then print("Setting up Defense battle") SetStartFleetSuffix("Defense") elseif (GetGameSettingAsString("startwith") == "Construction") then print("Setting up Construction battle") SetStartFleetSuffix("Construction") elseif (GetGameSettingAsString("startwith") == "none") then print("Setting up GCO MAP") SetStartFleetSuffix("none") end print("MUSIC=====================================") if (GetGameSettingAsNumber("Play_Rnd_Music") == 1) then print("MUSIC ON") Rule_Add("PickRandomMusicTrackRule") end end ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- --Resource Injection Rule ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- function ResourceInjectionRule() local resourcesToInject = GetGameSettingAsNumber("resourceinjection") print("LumpSum: "..resourcesToInject.." resources") local playerIndex = 0 local playerCount = Universe_PlayerCount(); while (playerIndex < playerCount) do if (Player_IsAlive(playerIndex) == 1) then local currentResources = Player_GetRU(playerIndex) if(currentResources + resourcesToInject < 2000000) then Player_SetRU(playerIndex, currentResources + resourcesToInject) else Player_SetRU(playerIndex, 2000000) end end playerIndex = playerIndex + 1 end end ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- --Resource Lump sum rule ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- function ResourceLumpSumRule() local resourcesToInject = GetGameSettingAsNumber("resourcelumpsum") print("LumpSum: "..resourcesToInject.." resources") local playerIndex = 0 local playerCount = Universe_PlayerCount(); while (playerIndex < playerCount) do if (Player_IsAlive(playerIndex) == 1) then local currentResources = Player_GetRU(playerIndex) if(currentResources + resourcesToInject < 2000000) then Player_SetRU(playerIndex, currentResources + resourcesToInject) else Player_SetRU(playerIndex, 2000000) end end playerIndex = playerIndex + 1 end Rule_Remove("ResourceLumpSumRule") end ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- --Capture checking rule ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- function CheckCaptureStatusRule() --see if any caputuring ships not correct owner local groupName = "captureGroup_"..capturePlayerIndex local groupCount = SobGroup_Count(groupName) if (Player_IsAlive(capturePlayerIndex)) then --local position = {0,0,0} if (groupCount > 0) then print("Player "..capturePlayerIndex.." has ships being captured.") local playerCount = Universe_PlayerCount(); local playerIndex = 0; while (playerIndex < playerCount) do --for each other player if (playerIndex ~= capturePlayerIndex and Player_IsAlive(playerIndex) == 1) then if (SobGroup_CountByPlayer(groupName, playerIndex) > 0) then --a ship that was being captured has changed owner -- ..wait a while before killing player Player_Kill(capturePlayerIndex) --announce ship loss if current player if (Universe_CurrentPlayer() == capturePlayerIndex) then Sound_SpeechPlay("data:sound\\speech\\allships\\HEIDI\\ShipStolen") end end end -- go to next player playerIndex = playerIndex+1 end end --update list of any ships this player owns that are being captured SobGroup_GetSobGroupBeingCapturedGroup("Player_Ships"..capturePlayerIndex, groupName); end --rotate to next player for the next frame capturePlayerIndex = capturePlayerIndex + 1 if (capturePlayerIndex >= Universe_PlayerCount()) then capturePlayerIndex = 0 end end ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- --function for no resourcing ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- function DestroyResourcersRule() --destroy any resourcers SobGroup_Clear("ResourcersToDestroy") Player_FillShipsByType("ResourcersToDestroy", destroyResourcerIndex, "Hgn_ResourceCollector") if (SobGroup_Empty("ResourcersToDestroy") == 0) then SobGroup_Despawn("ResourcersToDestroy") end SobGroup_Clear("ResourcersToDestroy") Player_FillShipsByType("ResourcersToDestroy", destroyResourcerIndex, "Vgr_ResourceCollector") if (SobGroup_Empty("ResourcersToDestroy") == 0) then SobGroup_Despawn("ResourcersToDestroy") end SobGroup_Clear("ResourcersToDestroy") Player_FillShipsByType("ResourcersToDestroy", destroyResourcerIndex, "Imp_Mole_Miner") if (SobGroup_Empty("ResourcersToDestroy") == 0) then SobGroup_Despawn("ResourcersToDestroy") end SobGroup_Clear("ResourcersToDestroy") Player_FillShipsByType("ResourcersToDestroy", destroyResourcerIndex, "Reb_Mole_Miner") if (SobGroup_Empty("ResourcersToDestroy") == 0) then SobGroup_Despawn("ResourcersToDestroy") end --rotate to next player for the next frame destroyResourcerIndex = destroyResourcerIndex + 1 if (destroyResourcerIndex >= Universe_PlayerCount()) then destroyResourcerIndex = 0 end end ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- --Check if player has production ability ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- function CheckMothershipDeadRule() local playerCount = Universe_PlayerCount(); local playerIndex = 0; --check to see if there are any production ships left while (playerIndex < playerCount) do if (Player_IsAlive(playerIndex) == 1 and Player_HasShipWithBuildQueue(playerIndex)==0) then Player_Kill(playerIndex) end playerIndex = playerIndex+1 end end function CheckDeadRule() local playerCount = Universe_PlayerCount(); local playerIndex = 0; --check to see if there are any production ships left while (playerIndex < playerCount) do --need to check a timer here if (Player_IsAlive(playerIndex) == 1 and Player_NumberOfAwakeShips(playerIndex)==0) then Player_Kill(playerIndex) end playerIndex = playerIndex+1 end end ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- --Grants players all research ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- function GrantResearchRule() local playerIndex = 0 local playerCount = Universe_PlayerCount(); print("OMG RESEARCH") while (playerIndex < playerCount) do print("GIVING " .. playerIndex .. "ALL RESEARCH") --DisableListOfBuilds(playerIndex, ResearchModules) Player_GrantAllResearch(playerIndex) print ("DONE") playerIndex = playerIndex+1 end print("REALLY DONE") Rule_Remove("GrantResearchRule") end ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- --main rule ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- function MainRule() local playerIndex = 0; local playerCount = Universe_PlayerCount(); local numAlive = 0; local numEnemies = 0; local gameOver = 1; -- check to see if ALL of our enemies are dead local playerIndex = 0; while (playerIndex < playerCount) do -- and gameOver -- only process 'alive' players if (Player_IsAlive(playerIndex)==1) then -- compare this player against all others local otherPlayerIndex = 0; while (otherPlayerIndex < playerCount) do -- are enemies? if (AreAllied(playerIndex, otherPlayerIndex) == 0) then -- is the enemy alive - if so the game is still on if (Player_IsAlive(otherPlayerIndex)==1) then gameOver = 0 else numEnemies = numEnemies + 1 end end otherPlayerIndex = otherPlayerIndex+1; end numAlive = numAlive + 1; end -- go to next player playerIndex = playerIndex+1 end -- special case - if there are no enemies then never end if (numEnemies == 0 and numAlive>0) then gameOver = 0; end -- if gameOver flag is still set then the game is OVER if (gameOver==1) then Rule_Add("waitForEnd") Event_Start("endGame") Rule_Remove("MainRule") end end ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- --Helper util to kill the game ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- function waitForEnd() if(Event_IsDone("endGame")) then setGameOver() Rule_Remove("waitForEnd") end end function PickRandomMusicTrackRule() local randNum = 0 local musicDir = "" mode = 0 dofilepath("data:scripts/scar/playlist.lua") if(score_flag) then if (mode == 0) then tracks=track_count randNum = random(tracks) if (randNum < battleIDX) then musicDir = "ambient/" else musicDir = "battle/" end elseif (mode == 1) then tracks=battleIDX randNum = random(tracks) musicDir = "ambient/" elseif (mode == 2) then tracks=battleIDX-track_count randNum = random(tracks) musicDir = "battle/" end local track_length = musicTable[randNum].length local track_path = musicTable[randNum].path local track_name = musicTable[randNum].name Sound_MusicPlay(music_path .. musicDir .. track_path) print([[Level music (]] .. randNum .. [[): "]] .. track_name .. [["]]) Rule_Remove("PickRandomMusicTrackRule") Rule_AddInterval("PickRandomMusicTrackRule", track_length) else local track_length = musicTable[1].length local track_path = musicTable[1].path local track_name = musicTable[1].name Sound_MusicPlay(music_path .. musicDir .. track_path) end end function DisableListOfBuilds(playerIndex, buildlist) for k,buildOption in buildlist do print("Disable Ship: "..buildOption.." "..playerIndex) Player_RestrictBuildOption(playerIndex, buildOption) end end function DisableListOfResearch(playerIndex, researchlist) for k,researchEntry in researchlist do print("Disable Research: "..researchEntry.." "..playerIndex) Player_RestrictResearchOption(playerIndex, buildOption) end end ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- --Don't know if this is necessary ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- Events = {} -- the name of this table must always be Events - this is what the game looks for Events.endGame = { { { "wID = Wait_Start(5)","Wait_End(wID)"}, }, }