From b545dae476bb4e5deaa5ef24317c31b769a7f1a7 Mon Sep 17 00:00:00 2001 From: Luashine <103937213+Luashine@users.noreply.github.com> Date: Sat, 15 Oct 2022 19:15:48 +0200 Subject: [PATCH] Update for 24-player support. Fixes PBug90/w3gPlus#1 --- vjass/MapMetaDataLibrary.vjass | 36 +++++++++++++-------- vjass/W3GPlus.vjass | 58 ++++++++++++++++++++++++---------- 2 files changed, 64 insertions(+), 30 deletions(-) diff --git a/vjass/MapMetaDataLibrary.vjass b/vjass/MapMetaDataLibrary.vjass index 4c3558a..2d34499 100644 --- a/vjass/MapMetaDataLibrary.vjass +++ b/vjass/MapMetaDataLibrary.vjass @@ -200,14 +200,17 @@ library MMD initializer init ///Returns true for a fixed size uniform random subset of players in the game private function isEmitter takes nothing returns boolean + local player p = null local integer i = 0 local integer n = 0 local integer r local integer array picks local boolean array pick_flags loop - exitwhen i >= 12 - if GetPlayerController(Player(i)) == MAP_CONTROL_USER and GetPlayerSlotState(Player(i)) == PLAYER_SLOT_STATE_PLAYING then + exitwhen i >= bj_MAX_PLAYERS + set p = Player(i) + + if GetPlayerController(p) == MAP_CONTROL_USER and GetPlayerSlotState(p) == PLAYER_SLOT_STATE_PLAYING then if n < num_senders then //initializing picks set picks[n] = i set pick_flags[i] = true @@ -223,6 +226,8 @@ library MMD initializer init endif set i = i + 1 endloop + + set p = null return pick_flags[GetPlayerId(GetLocalPlayer())] endfunction @@ -319,8 +324,8 @@ library MMD initializer init ///Updates the value of a defined variable for a given player private function update_value takes string name, player p, string op, string value, integer val_type returns nothing local integer id = GetPlayerId(p) - if p == null or id < 0 or id >= 12 then - call BJDebugMsg("MMD Set Error: Invalid player. Must be P1 to P12.") + if p == null or id < 0 or id >= bj_MAX_PLAYERS then + call BJDebugMsg("MMD Set Error: Invalid player ID=" + I2S(id) + ". Must be 0 to " + I2S(bj_MAX_PLAYERS-1) + ".") elseif val_type != GetStoredInteger(gc, "types", name) then call BJDebugMsg("MMD Set Error: Updated value of undefined variable or used value of incorrect type.") elseif StringLength(op) == 0 then @@ -361,11 +366,11 @@ library MMD initializer init public function FlagPlayer takes player p, integer flag_type returns nothing local string flag = flags[flag_type] local integer id = GetPlayerId(p) - if p == null or id < 0 or id >= 12 then - call BJDebugMsg("MMD Flag Error: Invalid player. Must be P1 to P12.") + if p == null or id < 0 or id >= bj_MAX_PLAYERS then + call BJDebugMsg("MMD Flag Error: Invalid player ID=" + I2S(id) + ". Must be 0 to " + I2S(bj_MAX_PLAYERS-1) + ".") elseif StringLength(flag) == 0 then call BJDebugMsg("MMD Flag Error: Unrecognized flag type.") - elseif GetPlayerController(Player(id)) == MAP_CONTROL_USER then + elseif GetPlayerController(p) == MAP_CONTROL_USER then call emit("FlagP " + I2S(id) + " " + flag) endif endfunction @@ -448,17 +453,20 @@ library MMD initializer init ///Emits initialization data private function init2 takes nothing returns nothing - local integer i - local trigger t + local integer maxPlayerId = bj_MAX_PLAYERS - 1 + local integer i = 0 + local player p = null + local trigger t = null set initialized = true call emit("init version " + I2S(MINIMUM_PARSER_VERSION) + " " + I2S(CURRENT_VERSION)) - set i = 0 loop - exitwhen i >= 12 - if GetPlayerController(Player(i)) == MAP_CONTROL_USER and GetPlayerSlotState(Player(i)) == PLAYER_SLOT_STATE_PLAYING then - call emit("init pid " + I2S(i) + " " + pack(GetPlayerName(Player(i)))) + exitwhen i > maxPlayerId + set p = Player(i) + + if GetPlayerController(p) == MAP_CONTROL_USER and GetPlayerSlotState(p) == PLAYER_SLOT_STATE_PLAYING then + call emit("init pid " + I2S(i) + " " + pack(GetPlayerName(p))) endif set i = i + 1 endloop @@ -466,6 +474,8 @@ library MMD initializer init set t = CreateTrigger() call TriggerAddAction(t, function tick) call TriggerRegisterTimerEvent(t, 0.37, true) + + set p = null endfunction ///Places init2 on a timer, initializes game cache, and translates constants diff --git a/vjass/W3GPlus.vjass b/vjass/W3GPlus.vjass index 5db57d6..cbb601b 100644 --- a/vjass/W3GPlus.vjass +++ b/vjass/W3GPlus.vjass @@ -37,17 +37,23 @@ library W3GPlus initializer init requires MMD endfunction function action_resourceTimerTimeout takes nothing returns nothing + local integer maxPlayerId = bj_MAX_PLAYERS - 1 local integer i = 0 + local player p = null + loop - exitwhen i > 11 - if GetPlayerSlotState(Player(i)) == PLAYER_SLOT_STATE_PLAYING and not IsPlayerObserver(Player(i)) then - call MMD_LogEvent3("gold_mined_total",I2S(i),I2S(GetPlayerScore(Player(i),PLAYER_SCORE_GOLD_MINED_TOTAL)),I2S(execution_count)) - call MMD_LogEvent3("gold_mined_upkeep",I2S(i),I2S(GetPlayerScore(Player(i),PLAYER_SCORE_GOLD_MINED_UPKEEP)),I2S(execution_count)) - call MMD_LogEvent3("gold_mined_upkeep",I2S(i),I2S(GetPlayerScore(Player(i),PLAYER_SCORE_LUMBER_TOTAL)),I2S(execution_count)) + exitwhen i > maxPlayerId + set p = Player(i) + + if GetPlayerSlotState(p) == PLAYER_SLOT_STATE_PLAYING and not IsPlayerObserver(p) then + call MMD_LogEvent3("gold_mined_total",I2S(i),I2S(GetPlayerScore(p,PLAYER_SCORE_GOLD_MINED_TOTAL)),I2S(execution_count)) + call MMD_LogEvent3("gold_mined_upkeep",I2S(i),I2S(GetPlayerScore(p,PLAYER_SCORE_GOLD_MINED_UPKEEP)),I2S(execution_count)) + call MMD_LogEvent3("gold_mined_upkeep",I2S(i),I2S(GetPlayerScore(p,PLAYER_SCORE_LUMBER_TOTAL)),I2S(execution_count)) endif - set i = i +1 + set i = i + 1 endloop set execution_count = execution_count + 1 + set p = null endfunction private function action_increaseElapsedSeconds takes nothing returns nothing @@ -56,7 +62,12 @@ library W3GPlus initializer init requires MMD //DefineEvent2(name, format, argName1, argName2) private function init2 takes nothing returns nothing + local integer maxPlayerId = bj_MAX_PLAYERS - 1 local integer i = 0 + local player p = null + local race prace = null + local string raceName = "" + //call MMD_DefineEvent2("unit_created","{0} {1}","pid","uid") call MMD_DefineEvent3("gold_mined_total","{0} {1}","pid","amount","exec_count") call MMD_DefineEvent3("gold_mined_upkeep","{0} {1}","pid","amount","exec_count") @@ -68,23 +79,36 @@ library W3GPlus initializer init requires MMD call MMD_DefineValue("race",MMD_TYPE_STRING,MMD_GOAL_NONE,MMD_SUGGEST_NONE) loop - exitwhen i > 11 - if (not IsPlayerObserver(Player(i))) and GetPlayerSlotState(Player(i))==PLAYER_SLOT_STATE_PLAYING then - if (GetPlayerRace(Player(i)))==RACE_HUMAN then - call MMD_UpdateValueString("race",Player(i),"human") - elseif (GetPlayerRace(Player(i)))==RACE_ORC then - call MMD_UpdateValueString("race",Player(i),"orc") - elseif (GetPlayerRace(Player(i)))==RACE_UNDEAD then - call MMD_UpdateValueString("race",Player(i),"undead") - elseif (GetPlayerRace(Player(i)))==RACE_NIGHTELF then - call MMD_UpdateValueString("race",Player(i),"nightelf") - endif + exitwhen i > maxPlayerId + set p = Player(i) + if (not IsPlayerObserver(p)) and GetPlayerSlotState(p)==PLAYER_SLOT_STATE_PLAYING then + set prace = GetPlayerRace(p) + if prace==RACE_HUMAN then + set raceName = "human" + elseif prace==RACE_ORC then + set raceName = "orc" + elseif prace==RACE_UNDEAD then + set raceName = "undead" + elseif prace==RACE_NIGHTELF then + set raceName = "nightelf" + elseif prace==RACE_DEMON then + set raceName = "demon" + elseif prace==RACE_OTHER then + set raceName = "other" + else + set raceName = "unknown" + endif + + call MMD_UpdateValueString("race",p,raceName) endif set i = i + 1 endloop + + set p = null + set prace = null endfunction