From 4cb0e701844b004cb4b4daf55e0679b4b850e4c9 Mon Sep 17 00:00:00 2001 From: Frank Date: Thu, 8 Jun 2023 09:43:11 +0200 Subject: [PATCH 1/2] Update RAT.lua - Fixed RATMANAGER spamming due to not accounting for planned/scheduled groups --- Moose Development/Moose/Functional/RAT.lua | 31 +++++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/Moose Development/Moose/Functional/RAT.lua b/Moose Development/Moose/Functional/RAT.lua index 081132413..98e295167 100644 --- a/Moose Development/Moose/Functional/RAT.lua +++ b/Moose Development/Moose/Functional/RAT.lua @@ -5832,6 +5832,7 @@ RATMANAGER={ rat={}, name={}, alive={}, + planned={}, min={}, nrat=0, ntot=nil, @@ -5880,6 +5881,7 @@ function RATMANAGER:Add(ratobject,min) self.rat[self.nrat]=ratobject self.alive[self.nrat]=0 + self.planned[self.nrat]=0 self.name[self.nrat]=ratobject.alias self.min[self.nrat]=min or 1 @@ -6020,11 +6022,25 @@ function RATMANAGER:_Manage() for i=1,self.nrat do for j=1,N[i] do time=time+self.dTspawn - SCHEDULER:New(nil, RAT._SpawnWithRoute, {self.rat[i]}, time) + self.planned[i]=self.planned[i]+1 + SCHEDULER:New(nil, RATMANAGER._Spawn, {self, i}, time) end end end +--- Instantly starts the RAT manager and spawns the initial random number RAT groups for each RAT object. +-- @param #RATMANAGER self +-- @param #RATMANAGER RATMANAGER self object. +-- @param #number i Index. +function RATMANAGER:_Spawn(i) + + local rat=self.rat[i] --#RAT + + rat:_SpawnWithRoute() + self.planned[i]=self.planned[i]-1 + +end + --- Counts the number of alive RAT objects. -- @param #RATMANAGER self function RATMANAGER:_Count() @@ -6053,7 +6069,7 @@ function RATMANAGER:_Count() ntotal=ntotal+n -- Debug output. - local text=string.format("Number of alive groups of %s = %d", self.name[i], n) + local text=string.format("Number of alive groups of %s = %d, planned=%d", self.name[i], n, self.planned[i]) self:T(RATMANAGER.id..text) end @@ -6083,9 +6099,10 @@ function RATMANAGER:_RollDice(nrat,ntot,min,alive) local M={} local P={} for i=1,nrat do + local a=alive[i]+self.planned[i] N[#N+1]=0 - M[#M+1]=math.max(alive[i], min[i]) - P[#P+1]=math.max(min[i]-alive[i],0) + M[#M+1]=math.max(a, min[i]) + P[#P+1]=math.max(min[i]-a,0) end -- Min/max group arrays. @@ -6102,7 +6119,7 @@ function RATMANAGER:_RollDice(nrat,ntot,min,alive) -- Number of new groups to be added. local nnew=ntot for i=1,nrat do - nnew=nnew-alive[i] + nnew=nnew-alive[i]-self.planned[i] end for i=1,nrat-1 do @@ -6134,7 +6151,7 @@ function RATMANAGER:_RollDice(nrat,ntot,min,alive) end -- Debug info - self:T3(string.format("RATMANAGER: i=%d, alive=%d, min=%d, mini=%d, maxi=%d, add=%d, sumN=%d, sumP=%d", j, alive[j], min[j], mini[j], maxi[j], N[j],sN, sP)) + self:T3(string.format("RATMANAGER: i=%d, alive=%d, planned=%d, min=%d, mini=%d, maxi=%d, add=%d, sumN=%d, sumP=%d", j, alive[j], self.planned[i], min[j], mini[j], maxi[j], N[j],sN, sP)) end @@ -6149,7 +6166,7 @@ function RATMANAGER:_RollDice(nrat,ntot,min,alive) -- Debug info local text=RATMANAGER.id.."\n" for i=1,nrat do - text=text..string.format("%s: i=%d, alive=%d, min=%d, mini=%d, maxi=%d, add=%d\n", self.name[i], i, alive[i], min[i], mini[i], maxi[i], N[i]) + text=text..string.format("%s: i=%d, alive=%d, planned=%d, min=%d, mini=%d, maxi=%d, add=%d\n", self.name[i], i, alive[i], self.planned[i], min[i], mini[i], maxi[i], N[i]) end text=text..string.format("Total # of groups to add = %d", sum(N, done)) self:T(text) From 2c14ee74b020bdca6cb1c3145b198e88120e0efb Mon Sep 17 00:00:00 2001 From: Applevangelist Date: Thu, 8 Jun 2023 13:58:22 +0200 Subject: [PATCH 2/2] #SCORING * Can leave text empty on some instances --- .../Moose/Functional/Scoring.lua | 45 ++++++++++--------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/Moose Development/Moose/Functional/Scoring.lua b/Moose Development/Moose/Functional/Scoring.lua index 3dda306a3..950ccd3c0 100644 --- a/Moose Development/Moose/Functional/Scoring.lua +++ b/Moose Development/Moose/Functional/Scoring.lua @@ -715,11 +715,11 @@ function SCORING:AddGoalScorePlayer( PlayerName, GoalTag, Text, Score ) PlayerData.Goals[GoalTag] = PlayerData.Goals[GoalTag] or { Score = 0 } PlayerData.Goals[GoalTag].Score = PlayerData.Goals[GoalTag].Score + Score PlayerData.Score = PlayerData.Score + Score - - MESSAGE:NewType( self.DisplayMessagePrefix .. Text, - MESSAGE.Type.Information ) - :ToAll() - + if Text then + MESSAGE:NewType( self.DisplayMessagePrefix .. Text, + MESSAGE.Type.Information ) + :ToAll() + end self:ScoreCSV( PlayerName, "", "GOAL_" .. string.upper( GoalTag ), 1, Score, nil ) end end @@ -738,7 +738,7 @@ function SCORING:AddGoalScore( PlayerUnit, GoalTag, Text, Score ) local PlayerName = PlayerUnit:GetPlayerName() - self:F( { PlayerUnit.UnitName, PlayerName, GoalTag, Text, Score } ) + self:T2( { PlayerUnit.UnitName, PlayerName, GoalTag, Text, Score } ) -- PlayerName can be nil, if the Unit with the player crashed or due to another reason. if PlayerName then @@ -747,11 +747,12 @@ function SCORING:AddGoalScore( PlayerUnit, GoalTag, Text, Score ) PlayerData.Goals[GoalTag] = PlayerData.Goals[GoalTag] or { Score = 0 } PlayerData.Goals[GoalTag].Score = PlayerData.Goals[GoalTag].Score + Score PlayerData.Score = PlayerData.Score + Score - - MESSAGE:NewType( self.DisplayMessagePrefix .. Text, + + if Text then + MESSAGE:NewType( self.DisplayMessagePrefix .. Text, MESSAGE.Type.Information ) :ToAll() - + end self:ScoreCSV( PlayerName, "", "GOAL_" .. string.upper( GoalTag ), 1, Score, PlayerUnit:GetName() ) end end @@ -784,11 +785,12 @@ function SCORING:_AddMissionTaskScore( Mission, PlayerUnit, Text, Score ) PlayerData.Score = self.Players[PlayerName].Score + Score PlayerData.Mission[MissionName].ScoreTask = self.Players[PlayerName].Mission[MissionName].ScoreTask + Score - - MESSAGE:NewType( self.DisplayMessagePrefix .. Mission:GetText() .. " : " .. Text .. " Score: " .. Score, - MESSAGE.Type.Information ) - :ToAll() - + + if Text then + MESSAGE:NewType( self.DisplayMessagePrefix .. Mission:GetText() .. " : " .. Text .. " Score: " .. Score, + MESSAGE.Type.Information ) + :ToAll() + end self:ScoreCSV( PlayerName, "", "TASK_" .. MissionName:gsub( ' ', '_' ), 1, Score, PlayerUnit:GetName() ) end end @@ -820,9 +822,11 @@ function SCORING:_AddMissionGoalScore( Mission, PlayerName, Text, Score ) PlayerData.Score = self.Players[PlayerName].Score + Score PlayerData.Mission[MissionName].ScoreTask = self.Players[PlayerName].Mission[MissionName].ScoreTask + Score - - MESSAGE:NewType( string.format( "%s%s: %s! Player %s receives %d score!", self.DisplayMessagePrefix, Mission:GetText(), Text, PlayerName, Score ), MESSAGE.Type.Information ):ToAll() - + + if Text then + MESSAGE:NewType( string.format( "%s%s: %s! Player %s receives %d score!", self.DisplayMessagePrefix, Mission:GetText(), Text, PlayerName, Score ), MESSAGE.Type.Information ):ToAll() + end + self:ScoreCSV( PlayerName, "", "TASK_" .. MissionName:gsub( ' ', '_' ), 1, Score ) end end @@ -847,11 +851,12 @@ function SCORING:_AddMissionScore( Mission, Text, Score ) PlayerData.Score = PlayerData.Score + Score PlayerData.Mission[MissionName].ScoreMission = PlayerData.Mission[MissionName].ScoreMission + Score - - MESSAGE:NewType( self.DisplayMessagePrefix .. "Player '" .. PlayerName .. "' has " .. Text .. " in " .. Mission:GetText() .. ". " .. Score .. " mission score!", + + if Text then + MESSAGE:NewType( self.DisplayMessagePrefix .. "Player '" .. PlayerName .. "' has " .. Text .. " in " .. Mission:GetText() .. ". " .. Score .. " mission score!", MESSAGE.Type.Information ) :ToAll() - + end self:ScoreCSV( PlayerName, "", "MISSION_" .. MissionName:gsub( ' ', '_' ), 1, Score ) end end