Restored old CleanUp and Scoring

This commit is contained in:
Frank
2020-04-24 16:55:15 +02:00
parent 2745c6c1ca
commit ac975e7e86
2 changed files with 390 additions and 656 deletions
+9 -13
View File
@@ -134,7 +134,7 @@ function CLEANUP_AIRBASE:New( AirbaseNames )
for UnitName, Unit in pairs( _DATABASE.UNITS ) do for UnitName, Unit in pairs( _DATABASE.UNITS ) do
local Unit = Unit -- Wrapper.Unit#UNIT local Unit = Unit -- Wrapper.Unit#UNIT
if Unit:IsAlive() ~= nil then if Unit:IsAlive() ~= nil then
if self.__:IsInAirbase( Unit:GetVec2() ) then if self:IsInAirbase( Unit:GetVec2() ) then
self:F( { UnitName = UnitName } ) self:F( { UnitName = UnitName } )
self.CleanUpList[UnitName] = {} self.CleanUpList[UnitName] = {}
self.CleanUpList[UnitName].CleanUpUnit = Unit self.CleanUpList[UnitName].CleanUpUnit = Unit
@@ -187,10 +187,6 @@ function CLEANUP_AIRBASE:SetCleanMissiles( CleanMissiles )
end end
end end
--- Check whether a Vec2 is in any cleanup airbase.
-- @param #CLEANUP_AIRBASE self
-- @param DCS#VEC2 Vec2 2D vector.
function CLEANUP_AIRBASE.__:IsInAirbase( Vec2 ) function CLEANUP_AIRBASE.__:IsInAirbase( Vec2 )
local InAirbase = false local InAirbase = false
@@ -198,7 +194,7 @@ function CLEANUP_AIRBASE.__:IsInAirbase( Vec2 )
local Airbase = Airbase -- Wrapper.Airbase#AIRBASE local Airbase = Airbase -- Wrapper.Airbase#AIRBASE
if Airbase:GetZone():IsVec2InZone( Vec2 ) then if Airbase:GetZone():IsVec2InZone( Vec2 ) then
InAirbase = true InAirbase = true
break break;
end end
end end
@@ -250,7 +246,7 @@ function CLEANUP_AIRBASE.__:OnEventBirth( EventData )
self:F( { EventData } ) self:F( { EventData } )
if EventData.IniUnit:IsAlive() ~= nil then if EventData.IniUnit:IsAlive() ~= nil then
if self.__:IsInAirbase( EventData.IniUnit:GetVec2() ) then if self:IsInAirbase( EventData.IniUnit:GetVec2() ) then
self.CleanUpList[EventData.IniDCSUnitName] = {} self.CleanUpList[EventData.IniDCSUnitName] = {}
self.CleanUpList[EventData.IniDCSUnitName].CleanUpUnit = EventData.IniUnit self.CleanUpList[EventData.IniDCSUnitName].CleanUpUnit = EventData.IniUnit
self.CleanUpList[EventData.IniDCSUnitName].CleanUpGroup = EventData.IniGroup self.CleanUpList[EventData.IniDCSUnitName].CleanUpGroup = EventData.IniGroup
@@ -295,7 +291,7 @@ function CLEANUP_AIRBASE.__:OnEventShot( Event )
self:F( { Event } ) self:F( { Event } )
-- Test if the missile was fired within one of the CLEANUP_AIRBASE.AirbaseNames. -- Test if the missile was fired within one of the CLEANUP_AIRBASE.AirbaseNames.
if self.__:IsInAirbase( Event.IniUnit:GetVec2() ) then if self:IsInAirbase( Event.IniUnit:GetVec2() ) then
-- Okay, the missile was fired within the CLEANUP_AIRBASE.AirbaseNames, destroy the fired weapon. -- Okay, the missile was fired within the CLEANUP_AIRBASE.AirbaseNames, destroy the fired weapon.
self:DestroyMissile( Event.Weapon ) self:DestroyMissile( Event.Weapon )
end end
@@ -308,7 +304,7 @@ function CLEANUP_AIRBASE.__:OnEventHit( Event )
self:F( { Event } ) self:F( { Event } )
if Event.IniUnit then if Event.IniUnit then
if self.__:IsInAirbase( Event.IniUnit:GetVec2() ) then if self:IsInAirbase( Event.IniUnit:GetVec2() ) then
self:T( { "Life: ", Event.IniDCSUnitName, ' = ', Event.IniUnit:GetLife(), "/", Event.IniUnit:GetLife0() } ) self:T( { "Life: ", Event.IniDCSUnitName, ' = ', Event.IniUnit:GetLife(), "/", Event.IniUnit:GetLife0() } )
if Event.IniUnit:GetLife() < Event.IniUnit:GetLife0() then if Event.IniUnit:GetLife() < Event.IniUnit:GetLife0() then
self:T( "CleanUp: Destroy: " .. Event.IniDCSUnitName ) self:T( "CleanUp: Destroy: " .. Event.IniDCSUnitName )
@@ -318,7 +314,7 @@ function CLEANUP_AIRBASE.__:OnEventHit( Event )
end end
if Event.TgtUnit then if Event.TgtUnit then
if self.__:IsInAirbase( Event.TgtUnit:GetVec2() ) then if self:IsInAirbase( Event.TgtUnit:GetVec2() ) then
self:T( { "Life: ", Event.TgtDCSUnitName, ' = ', Event.TgtUnit:GetLife(), "/", Event.TgtUnit:GetLife0() } ) self:T( { "Life: ", Event.TgtDCSUnitName, ' = ', Event.TgtUnit:GetLife(), "/", Event.TgtUnit:GetLife0() } )
if Event.TgtUnit:GetLife() < Event.TgtUnit:GetLife0() then if Event.TgtUnit:GetLife() < Event.TgtUnit:GetLife0() then
self:T( "CleanUp: Destroy: " .. Event.TgtDCSUnitName ) self:T( "CleanUp: Destroy: " .. Event.TgtDCSUnitName )
@@ -360,7 +356,7 @@ function CLEANUP_AIRBASE.__:EventAddForCleanUp( Event )
if Event.IniDCSUnit and Event.IniCategory == Object.Category.UNIT then if Event.IniDCSUnit and Event.IniCategory == Object.Category.UNIT then
if self.CleanUpList[Event.IniDCSUnitName] == nil then if self.CleanUpList[Event.IniDCSUnitName] == nil then
if self.__:IsInAirbase( Event.IniUnit:GetVec2() ) then if self:IsInAirbase( Event.IniUnit:GetVec2() ) then
self:AddForCleanUp( Event.IniUnit, Event.IniDCSUnitName ) self:AddForCleanUp( Event.IniUnit, Event.IniDCSUnitName )
end end
end end
@@ -368,7 +364,7 @@ function CLEANUP_AIRBASE.__:EventAddForCleanUp( Event )
if Event.TgtDCSUnit and Event.TgtCategory == Object.Category.UNIT then if Event.TgtDCSUnit and Event.TgtCategory == Object.Category.UNIT then
if self.CleanUpList[Event.TgtDCSUnitName] == nil then if self.CleanUpList[Event.TgtDCSUnitName] == nil then
if self.__:IsInAirbase( Event.TgtUnit:GetVec2() ) then if self:IsInAirbase( Event.TgtUnit:GetVec2() ) then
self:AddForCleanUp( Event.TgtUnit, Event.TgtDCSUnitName ) self:AddForCleanUp( Event.TgtUnit, Event.TgtDCSUnitName )
end end
end end
@@ -390,7 +386,7 @@ function CLEANUP_AIRBASE.__:CleanUpSchedule()
if CleanUpUnit:IsAlive() ~= nil then if CleanUpUnit:IsAlive() ~= nil then
if self.__:IsInAirbase( CleanUpUnit:GetVec2() ) then if self:IsInAirbase( CleanUpUnit:GetVec2() ) then
if _DATABASE:GetStatusGroup( CleanUpGroupName ) ~= "ReSpawn" then if _DATABASE:GetStatusGroup( CleanUpGroupName ) ~= "ReSpawn" then
+141 -403
View File
@@ -151,7 +151,7 @@
-- --
-- When a player commits too much damage to friendlies, his penalty score will reach a certain level. -- When a player commits too much damage to friendlies, his penalty score will reach a certain level.
-- Use the method @{#SCORING.SetFratricide}() to define the level when a player gets kicked. -- Use the method @{#SCORING.SetFratricide}() to define the level when a player gets kicked.
-- By default, the fratricide level is the default penalty multiplier * 2 for the penalty score. -- By default, the fratricide level is the default penalty mutiplier * 2 for the penalty score.
-- --
-- # Penalty score when a player changes the coalition. -- # Penalty score when a player changes the coalition.
-- --
@@ -227,12 +227,10 @@ SCORING = {
ClassName = "SCORING", ClassName = "SCORING",
ClassID = 0, ClassID = 0,
Players = {}, Players = {},
CSVdata = {},
} }
local _SCORINGCoalition = local _SCORINGCoalition =
{ {
[0] = "Neutral",
[1] = "Red", [1] = "Red",
[2] = "Blue", [2] = "Blue",
} }
@@ -246,35 +244,16 @@ local _SCORINGCategory =
[Unit.Category.STRUCTURE] = "Structure", [Unit.Category.STRUCTURE] = "Structure",
} }
--- Player data.
-- @type SCORING.PlayerData
-- @field #table Hit Player hits table.
-- @field #table Destroy Player destroy table.
-- @field #table Goals Player goals table.
-- @field #table Mission Player mission table.
-- @field #table HitPlayers Player hit other player table.
-- @field #number Score Player score.
-- @field #number Penalty Player penalties.
-- @field #number PenaltyCoalition Penalty for changing coalition.
-- @field #number PenaltyWarning Penalty warning.
-- @field #string UnitName Name of player unit.
-- @field #string UnitCoalition Coalition of player.
-- @field #string UnitType Type of player Unit.
-- @field #string ThreadLevel Thread level of player unit.
-- @field #string ThreadType Thread type of player unit.
--- Creates a new SCORING object to administer the scoring achieved by players. --- Creates a new SCORING object to administer the scoring achieved by players.
-- @param #SCORING self -- @param #SCORING self
-- @param #string GameName The name of the game. This name is also logged in the CSV score file. -- @param #string GameName The name of the game. This name is also logged in the CSV score file.
-- @param #string FileName (Optional) Name of the CSV file for saving results. If the file exists, player scores are read.
-- @param #boolean MenuOff (Optional) Done create player menus.
-- @return #SCORING self -- @return #SCORING self
-- @usage -- @usage
-- --
-- -- Define a new scoring object for the mission Gori Valley. -- -- Define a new scoring object for the mission Gori Valley.
-- ScoringObject = SCORING:New( "Gori Valley" ) -- ScoringObject = SCORING:New( "Gori Valley" )
-- --
function SCORING:New( GameName, FileName, MenuOff ) function SCORING:New( GameName )
-- Inherits from BASE -- Inherits from BASE
local self = BASE:Inherit( self, BASE:New() ) -- #SCORING local self = BASE:Inherit( self, BASE:New() ) -- #SCORING
@@ -285,10 +264,6 @@ function SCORING:New( GameName, FileName, MenuOff )
error( "A game name must be given to register the scoring results" ) error( "A game name must be given to register the scoring results" )
end end
if FileName then
self.FileName = FileName
end
-- Additional Object scores -- Additional Object scores
self.ScoringObjects = {} self.ScoringObjects = {}
@@ -315,9 +290,6 @@ function SCORING:New( GameName, FileName, MenuOff )
self:SetDisplayMessagePrefix() self:SetDisplayMessagePrefix()
-- No player menus.
self.MenuOff=MenuOff
-- Event handlers -- Event handlers
self:HandleEvent( EVENTS.Dead, self._EventOnDeadOrCrash ) self:HandleEvent( EVENTS.Dead, self._EventOnDeadOrCrash )
self:HandleEvent( EVENTS.Crash, self._EventOnDeadOrCrash ) self:HandleEvent( EVENTS.Crash, self._EventOnDeadOrCrash )
@@ -340,7 +312,7 @@ function SCORING:New( GameName, FileName, MenuOff )
-- Create the CSV file. -- Create the CSV file.
self:OpenCSV( GameName, FileName ) self:OpenCSV( GameName )
return self return self
@@ -628,13 +600,11 @@ end
-- @param #SCORING self -- @param #SCORING self
-- @return #SCORING -- @return #SCORING
function SCORING:SetScoringMenu( ScoringGroup ) function SCORING:SetScoringMenu( ScoringGroup )
if not self.MenuOff then local Menu = MENU_GROUP:New( ScoringGroup, 'Scoring and Statistics' )
local Menu = MENU_GROUP:New( ScoringGroup, 'Scoring' ) local ReportGroupSummary = MENU_GROUP_COMMAND:New( ScoringGroup, 'Summary report players in group', Menu, SCORING.ReportScoreGroupSummary, self, ScoringGroup )
local ReportGroupSummary = MENU_GROUP_COMMAND:New( ScoringGroup, 'Summary report player', Menu, SCORING.ReportScoreGroupSummary, self, ScoringGroup ) local ReportGroupDetailed = MENU_GROUP_COMMAND:New( ScoringGroup, 'Detailed report players in group', Menu, SCORING.ReportScoreGroupDetailed, self, ScoringGroup )
local ReportGroupDetailed = MENU_GROUP_COMMAND:New( ScoringGroup, 'Detailed report player', Menu, SCORING.ReportScoreGroupDetailed, self, ScoringGroup ) local ReportToAllSummary = MENU_GROUP_COMMAND:New( ScoringGroup, 'Summary report all players', Menu, SCORING.ReportScoreAllSummary, self, ScoringGroup )
local ReportToAllSummary = MENU_GROUP_COMMAND:New( ScoringGroup, 'Summary all players', Menu, SCORING.ReportScoreAllSummary, self, ScoringGroup )
self:SetState( ScoringGroup, "ScoringMenu", Menu ) self:SetState( ScoringGroup, "ScoringMenu", Menu )
end
return self return self
end end
@@ -677,7 +647,6 @@ function SCORING:_AddPlayerFromUnit( UnitData )
if not self.Players[PlayerName].UnitCoalition then if not self.Players[PlayerName].UnitCoalition then
self.Players[PlayerName].UnitCoalition = UnitCoalition self.Players[PlayerName].UnitCoalition = UnitCoalition
else else
-- Player jumpt into a unit of the other coalition.
if self.Players[PlayerName].UnitCoalition ~= UnitCoalition then if self.Players[PlayerName].UnitCoalition ~= UnitCoalition then
self.Players[PlayerName].Penalty = self.Players[PlayerName].Penalty + 50 self.Players[PlayerName].Penalty = self.Players[PlayerName].Penalty + 50
self.Players[PlayerName].PenaltyCoalition = self.Players[PlayerName].PenaltyCoalition + 1 self.Players[PlayerName].PenaltyCoalition = self.Players[PlayerName].PenaltyCoalition + 1
@@ -685,8 +654,6 @@ function SCORING:_AddPlayerFromUnit( UnitData )
"(changed " .. self.Players[PlayerName].PenaltyCoalition .. " times the coalition). 50 Penalty points added.", "(changed " .. self.Players[PlayerName].PenaltyCoalition .. " times the coalition). 50 Penalty points added.",
MESSAGE.Type.Information MESSAGE.Type.Information
):ToAll() ):ToAll()
-- Write CSV.
self:ScoreCSV( PlayerName, "", "COALITION_PENALTY", 1, -50, self.Players[PlayerName].UnitName, _SCORINGCoalition[self.Players[PlayerName].UnitCoalition], _SCORINGCategory[self.Players[PlayerName].UnitCategory], self.Players[PlayerName].UnitType, self:ScoreCSV( PlayerName, "", "COALITION_PENALTY", 1, -50, self.Players[PlayerName].UnitName, _SCORINGCoalition[self.Players[PlayerName].UnitCoalition], _SCORINGCategory[self.Players[PlayerName].UnitCategory], self.Players[PlayerName].UnitType,
UnitName, _SCORINGCoalition[UnitCoalition], _SCORINGCategory[UnitCategory], UnitData:GetTypeName() ) UnitName, _SCORINGCoalition[UnitCoalition], _SCORINGCategory[UnitCategory], UnitData:GetTypeName() )
end end
@@ -1020,7 +987,7 @@ function SCORING:_EventOnHit( Event )
-- A target got hit, score it. -- A target got hit, score it.
-- Player contains the score data from self.Players[InitPlayerName] -- Player contains the score data from self.Players[InitPlayerName]
local Player = self.Players[InitPlayerName] --#SCORING.PlayerData local Player = self.Players[InitPlayerName]
-- Ensure there is a hit table per TargetCategory and TargetUnitName. -- Ensure there is a hit table per TargetCategory and TargetUnitName.
Player.Hit[TargetCategory] = Player.Hit[TargetCategory] or {} Player.Hit[TargetCategory] = Player.Hit[TargetCategory] or {}
@@ -1051,16 +1018,10 @@ function SCORING:_EventOnHit( Event )
if InitCoalition then -- A coalition object was hit. if InitCoalition then -- A coalition object was hit.
if InitCoalition == TargetCoalition then if InitCoalition == TargetCoalition then
------------------
-- Hit Friendly --
------------------
--
Player.Penalty = Player.Penalty + 10 Player.Penalty = Player.Penalty + 10
PlayerHit.Penalty = PlayerHit.Penalty + 10 PlayerHit.Penalty = PlayerHit.Penalty + 10
PlayerHit.PenaltyHit = PlayerHit.PenaltyHit + 1 PlayerHit.PenaltyHit = PlayerHit.PenaltyHit + 1
-- Check if target was another player.
if TargetPlayerName ~= nil then -- It is a player hitting another player ... if TargetPlayerName ~= nil then -- It is a player hitting another player ...
MESSAGE MESSAGE
:NewType( self.DisplayMessagePrefix .. "Player '" .. InitPlayerName .. "' hit friendly player '" .. TargetPlayerName .. "' " .. :NewType( self.DisplayMessagePrefix .. "Player '" .. InitPlayerName .. "' hit friendly player '" .. TargetPlayerName .. "' " ..
@@ -1080,21 +1041,11 @@ function SCORING:_EventOnHit( Event )
:ToAllIf( self:IfMessagesHit() and self:IfMessagesToAll() ) :ToAllIf( self:IfMessagesHit() and self:IfMessagesToAll() )
:ToCoalitionIf( InitCoalition, self:IfMessagesHit() and self:IfMessagesToCoalition() ) :ToCoalitionIf( InitCoalition, self:IfMessagesHit() and self:IfMessagesToCoalition() )
end end
-- Write penalty to CSV file.
self:ScoreCSV( InitPlayerName, TargetPlayerName, "HIT_PENALTY", 1, -10, InitUnitName, InitUnitCoalition, InitUnitCategory, InitUnitType, TargetUnitName, TargetUnitCoalition, TargetUnitCategory, TargetUnitType ) self:ScoreCSV( InitPlayerName, TargetPlayerName, "HIT_PENALTY", 1, -10, InitUnitName, InitUnitCoalition, InitUnitCategory, InitUnitType, TargetUnitName, TargetUnitCoalition, TargetUnitCategory, TargetUnitType )
else else
----------------
-- Hit Enemey --
----------------
Player.Score = Player.Score + 1 Player.Score = Player.Score + 1
PlayerHit.Score = PlayerHit.Score + 1 PlayerHit.Score = PlayerHit.Score + 1
PlayerHit.ScoreHit = PlayerHit.ScoreHit + 1 PlayerHit.ScoreHit = PlayerHit.ScoreHit + 1
-- Check if it was a player.
if TargetPlayerName ~= nil then -- It is a player hitting another player ... if TargetPlayerName ~= nil then -- It is a player hitting another player ...
MESSAGE MESSAGE
:NewType( self.DisplayMessagePrefix .. "Player '" .. InitPlayerName .. "' hit enemy player '" .. TargetPlayerName .. "' " .. :NewType( self.DisplayMessagePrefix .. "Player '" .. InitPlayerName .. "' hit enemy player '" .. TargetPlayerName .. "' " ..
@@ -1114,21 +1065,15 @@ function SCORING:_EventOnHit( Event )
:ToAllIf( self:IfMessagesHit() and self:IfMessagesToAll() ) :ToAllIf( self:IfMessagesHit() and self:IfMessagesToAll() )
:ToCoalitionIf( InitCoalition, self:IfMessagesHit() and self:IfMessagesToCoalition() ) :ToCoalitionIf( InitCoalition, self:IfMessagesHit() and self:IfMessagesToCoalition() )
end end
-- Write score to CSV file. Score 1 PT.
self:ScoreCSV( InitPlayerName, TargetPlayerName, "HIT_SCORE", 1, 1, InitUnitName, InitUnitCoalition, InitUnitCategory, InitUnitType, TargetUnitName, TargetUnitCoalition, TargetUnitCategory, TargetUnitType ) self:ScoreCSV( InitPlayerName, TargetPlayerName, "HIT_SCORE", 1, 1, InitUnitName, InitUnitCoalition, InitUnitCategory, InitUnitType, TargetUnitName, TargetUnitCoalition, TargetUnitCategory, TargetUnitType )
end end
else -- A scenery object was hit. else -- A scenery object was hit.
MESSAGE MESSAGE
:NewType( self.DisplayMessagePrefix .. "Player '" .. InitPlayerName .. "' hit scenery object.", :NewType( self.DisplayMessagePrefix .. "Player '" .. InitPlayerName .. "' hit scenery object.",
MESSAGE.Type.Update MESSAGE.Type.Update
) )
:ToAllIf( self:IfMessagesHit() and self:IfMessagesToAll() ) :ToAllIf( self:IfMessagesHit() and self:IfMessagesToAll() )
:ToCoalitionIf( InitCoalition, self:IfMessagesHit() and self:IfMessagesToCoalition() ) :ToCoalitionIf( InitCoalition, self:IfMessagesHit() and self:IfMessagesToCoalition() )
-- Scenery gives 0 PT.
self:ScoreCSV( InitPlayerName, "", "HIT_SCORE", 1, 0, InitUnitName, InitUnitCoalition, InitUnitCategory, InitUnitType, TargetUnitName, "", "Scenery", TargetUnitType ) self:ScoreCSV( InitPlayerName, "", "HIT_SCORE", 1, 0, InitUnitName, InitUnitCoalition, InitUnitCategory, InitUnitType, TargetUnitName, "", "Scenery", TargetUnitType )
end end
end end
@@ -1141,11 +1086,8 @@ function SCORING:_EventOnHit( Event )
-- It is a weapon initiated by a player, that is hitting something -- It is a weapon initiated by a player, that is hitting something
-- This seems to occur only with scenery and static objects. -- This seems to occur only with scenery and static objects.
if Event.WeaponPlayerName ~= nil then if Event.WeaponPlayerName ~= nil then
self:_AddPlayerFromUnit( Event.WeaponUNIT ) self:_AddPlayerFromUnit( Event.WeaponUNIT )
if self.Players[Event.WeaponPlayerName] then -- This should normally not happen, but i'll test it anyway. if self.Players[Event.WeaponPlayerName] then -- This should normally not happen, but i'll test it anyway.
if TargetPlayerName ~= nil then -- It is a player hitting another player ... if TargetPlayerName ~= nil then -- It is a player hitting another player ...
self:_AddPlayerFromUnit( TargetUNIT ) self:_AddPlayerFromUnit( TargetUNIT )
end end
@@ -1182,7 +1124,6 @@ function SCORING:_EventOnHit( Event )
if InitCoalition then -- A coalition object was hit, probably a static. if InitCoalition then -- A coalition object was hit, probably a static.
if InitCoalition == TargetCoalition then if InitCoalition == TargetCoalition then
-- TODO: Penalty according scale -- TODO: Penalty according scale
Player.Penalty = Player.Penalty + 10 Player.Penalty = Player.Penalty + 10
PlayerHit.Penalty = PlayerHit.Penalty + 10 PlayerHit.Penalty = PlayerHit.Penalty + 10
@@ -1196,16 +1137,11 @@ function SCORING:_EventOnHit( Event )
) )
:ToAllIf( self:IfMessagesHit() and self:IfMessagesToAll() ) :ToAllIf( self:IfMessagesHit() and self:IfMessagesToAll() )
:ToCoalitionIf( Event.WeaponCoalition, self:IfMessagesHit() and self:IfMessagesToCoalition() ) :ToCoalitionIf( Event.WeaponCoalition, self:IfMessagesHit() and self:IfMessagesToCoalition() )
-- Minus 10 points.
self:ScoreCSV( Event.WeaponPlayerName, TargetPlayerName, "HIT_PENALTY", 1, -10, Event.WeaponName, Event.WeaponCoalition, Event.WeaponCategory, Event.WeaponTypeName, TargetUnitName, TargetUnitCoalition, TargetUnitCategory, TargetUnitType ) self:ScoreCSV( Event.WeaponPlayerName, TargetPlayerName, "HIT_PENALTY", 1, -10, Event.WeaponName, Event.WeaponCoalition, Event.WeaponCategory, Event.WeaponTypeName, TargetUnitName, TargetUnitCoalition, TargetUnitCategory, TargetUnitType )
else else
Player.Score = Player.Score + 1 Player.Score = Player.Score + 1
PlayerHit.Score = PlayerHit.Score + 1 PlayerHit.Score = PlayerHit.Score + 1
PlayerHit.ScoreHit = PlayerHit.ScoreHit + 1 PlayerHit.ScoreHit = PlayerHit.ScoreHit + 1
MESSAGE MESSAGE
:NewType( self.DisplayMessagePrefix .. "Player '" .. Event.WeaponPlayerName .. "' hit enemy target " .. :NewType( self.DisplayMessagePrefix .. "Player '" .. Event.WeaponPlayerName .. "' hit enemy target " ..
TargetUnitCategory .. " ( " .. TargetType .. " ) " .. TargetUnitCategory .. " ( " .. TargetType .. " ) " ..
@@ -1214,21 +1150,15 @@ function SCORING:_EventOnHit( Event )
) )
:ToAllIf( self:IfMessagesHit() and self:IfMessagesToAll() ) :ToAllIf( self:IfMessagesHit() and self:IfMessagesToAll() )
:ToCoalitionIf( Event.WeaponCoalition, self:IfMessagesHit() and self:IfMessagesToCoalition() ) :ToCoalitionIf( Event.WeaponCoalition, self:IfMessagesHit() and self:IfMessagesToCoalition() )
-- Score hit 1 PT.
self:ScoreCSV( Event.WeaponPlayerName, TargetPlayerName, "HIT_SCORE", 1, 1, Event.WeaponName, Event.WeaponCoalition, Event.WeaponCategory, Event.WeaponTypeName, TargetUnitName, TargetUnitCoalition, TargetUnitCategory, TargetUnitType ) self:ScoreCSV( Event.WeaponPlayerName, TargetPlayerName, "HIT_SCORE", 1, 1, Event.WeaponName, Event.WeaponCoalition, Event.WeaponCategory, Event.WeaponTypeName, TargetUnitName, TargetUnitCoalition, TargetUnitCategory, TargetUnitType )
end end
else -- A scenery object was hit. else -- A scenery object was hit.
MESSAGE MESSAGE
:NewType( self.DisplayMessagePrefix .. "Player '" .. Event.WeaponPlayerName .. "' hit scenery object.", :NewType( self.DisplayMessagePrefix .. "Player '" .. Event.WeaponPlayerName .. "' hit scenery object.",
MESSAGE.Type.Update MESSAGE.Type.Update
) )
:ToAllIf( self:IfMessagesHit() and self:IfMessagesToAll() ) :ToAllIf( self:IfMessagesHit() and self:IfMessagesToAll() )
:ToCoalitionIf( InitCoalition, self:IfMessagesHit() and self:IfMessagesToCoalition() ) :ToCoalitionIf( InitCoalition, self:IfMessagesHit() and self:IfMessagesToCoalition() )
-- Scenery hit 0 PT.
self:ScoreCSV( Event.WeaponPlayerName, "", "HIT_SCORE", 1, 0, Event.WeaponName, Event.WeaponCoalition, Event.WeaponCategory, Event.WeaponTypeName, TargetUnitName, "", "Scenery", TargetUnitType ) self:ScoreCSV( Event.WeaponPlayerName, "", "HIT_SCORE", 1, 0, Event.WeaponName, Event.WeaponCoalition, Event.WeaponCategory, Event.WeaponTypeName, TargetUnitName, "", "Scenery", TargetUnitType )
end end
end end
@@ -1311,11 +1241,6 @@ function SCORING:_EventOnDeadOrCrash( Event )
if TargetCoalition then if TargetCoalition then
if InitCoalition == TargetCoalition then if InitCoalition == TargetCoalition then
---
-- Hit Friendly
---
local ThreatLevelTarget = TargetThreatLevel local ThreatLevelTarget = TargetThreatLevel
local ThreatTypeTarget = TargetThreatType local ThreatTypeTarget = TargetThreatType
local ThreatLevelPlayer = Player.ThreatLevel / 10 + 1 local ThreatLevelPlayer = Player.ThreatLevel / 10 + 1
@@ -1346,16 +1271,10 @@ function SCORING:_EventOnDeadOrCrash( Event )
:ToCoalitionIf( InitCoalition, self:IfMessagesDestroy() and self:IfMessagesToCoalition() ) :ToCoalitionIf( InitCoalition, self:IfMessagesDestroy() and self:IfMessagesToCoalition() )
end end
-- Write CSV penalty.
Destroyed = true Destroyed = true
self:ScoreCSV( PlayerName, TargetPlayerName, "DESTROY_PENALTY", 1, ThreatPenalty, InitUnitName, InitUnitCoalition, InitUnitCategory, InitUnitType, TargetUnitName, TargetUnitCoalition, TargetUnitCategory, TargetUnitType ) self:ScoreCSV( PlayerName, TargetPlayerName, "DESTROY_PENALTY", 1, ThreatPenalty, InitUnitName, InitUnitCoalition, InitUnitCategory, InitUnitType, TargetUnitName, TargetUnitCoalition, TargetUnitCategory, TargetUnitType )
else else
---
-- Hit Enemy
---
local ThreatLevelTarget = TargetThreatLevel local ThreatLevelTarget = TargetThreatLevel
local ThreatTypeTarget = TargetThreatType local ThreatTypeTarget = TargetThreatType
local ThreatLevelPlayer = Player.ThreatLevel / 10 + 1 local ThreatLevelPlayer = Player.ThreatLevel / 10 + 1
@@ -1366,7 +1285,6 @@ function SCORING:_EventOnDeadOrCrash( Event )
Player.Score = Player.Score + ThreatScore Player.Score = Player.Score + ThreatScore
TargetDestroy.Score = TargetDestroy.Score + ThreatScore TargetDestroy.Score = TargetDestroy.Score + ThreatScore
TargetDestroy.ScoreDestroy = TargetDestroy.ScoreDestroy + 1 TargetDestroy.ScoreDestroy = TargetDestroy.ScoreDestroy + 1
if Player.HitPlayers[TargetPlayerName] then -- A player destroyed another player if Player.HitPlayers[TargetPlayerName] then -- A player destroyed another player
MESSAGE MESSAGE
:NewType( self.DisplayMessagePrefix .. "Player '" .. PlayerName .. "' destroyed enemy player '" .. TargetPlayerName .. "' " .. :NewType( self.DisplayMessagePrefix .. "Player '" .. PlayerName .. "' destroyed enemy player '" .. TargetPlayerName .. "' " ..
@@ -1386,21 +1304,14 @@ function SCORING:_EventOnDeadOrCrash( Event )
:ToAllIf( self:IfMessagesDestroy() and self:IfMessagesToAll() ) :ToAllIf( self:IfMessagesDestroy() and self:IfMessagesToAll() )
:ToCoalitionIf( InitCoalition, self:IfMessagesDestroy() and self:IfMessagesToCoalition() ) :ToCoalitionIf( InitCoalition, self:IfMessagesDestroy() and self:IfMessagesToCoalition() )
end end
-- Write CSV.
Destroyed = true Destroyed = true
self:ScoreCSV( PlayerName, TargetPlayerName, "DESTROY_SCORE", 1, ThreatScore, InitUnitName, InitUnitCoalition, InitUnitCategory, InitUnitType, TargetUnitName, TargetUnitCoalition, TargetUnitCategory, TargetUnitType ) self:ScoreCSV( PlayerName, TargetPlayerName, "DESTROY_SCORE", 1, ThreatScore, InitUnitName, InitUnitCoalition, InitUnitCategory, InitUnitType, TargetUnitName, TargetUnitCoalition, TargetUnitCategory, TargetUnitType )
local UnitName = TargetUnit:GetName() local UnitName = TargetUnit:GetName()
-- Scoring for special objects.
local Score = self.ScoringObjects[UnitName] local Score = self.ScoringObjects[UnitName]
if Score then if Score then
Player.Score = Player.Score + Score Player.Score = Player.Score + Score
TargetDestroy.Score = TargetDestroy.Score + Score TargetDestroy.Score = TargetDestroy.Score + Score
MESSAGE MESSAGE
:NewType( self.DisplayMessagePrefix .. "Special target '" .. TargetUnitCategory .. " ( " .. ThreatTypeTarget .. " ) " .. " destroyed! " .. :NewType( self.DisplayMessagePrefix .. "Special target '" .. TargetUnitCategory .. " ( " .. ThreatTypeTarget .. " ) " .. " destroyed! " ..
"Player '" .. PlayerName .. "' receives an extra " .. Score .. " points! Total: " .. Player.Score - Player.Penalty, "Player '" .. PlayerName .. "' receives an extra " .. Score .. " points! Total: " .. Player.Score - Player.Penalty,
@@ -1408,8 +1319,6 @@ function SCORING:_EventOnDeadOrCrash( Event )
) )
:ToAllIf( self:IfMessagesScore() and self:IfMessagesToAll() ) :ToAllIf( self:IfMessagesScore() and self:IfMessagesToAll() )
:ToCoalitionIf( InitCoalition, self:IfMessagesScore() and self:IfMessagesToCoalition() ) :ToCoalitionIf( InitCoalition, self:IfMessagesScore() and self:IfMessagesToCoalition() )
-- Write CSV file.
self:ScoreCSV( PlayerName, TargetPlayerName, "DESTROY_SCORE", 1, Score, InitUnitName, InitUnitCoalition, InitUnitCategory, InitUnitType, TargetUnitName, TargetUnitCoalition, TargetUnitCategory, TargetUnitType ) self:ScoreCSV( PlayerName, TargetPlayerName, "DESTROY_SCORE", 1, Score, InitUnitName, InitUnitCoalition, InitUnitCategory, InitUnitType, TargetUnitName, TargetUnitCoalition, TargetUnitCategory, TargetUnitType )
Destroyed = true Destroyed = true
end end
@@ -1417,16 +1326,11 @@ function SCORING:_EventOnDeadOrCrash( Event )
-- Check if there are Zones where the destruction happened. -- Check if there are Zones where the destruction happened.
for ZoneName, ScoreZoneData in pairs( self.ScoringZones ) do for ZoneName, ScoreZoneData in pairs( self.ScoringZones ) do
self:F( { ScoringZone = ScoreZoneData } ) self:F( { ScoringZone = ScoreZoneData } )
local ScoreZone = ScoreZoneData.ScoreZone -- Core.Zone#ZONE_BASE local ScoreZone = ScoreZoneData.ScoreZone -- Core.Zone#ZONE_BASE
local Score = ScoreZoneData.Score local Score = ScoreZoneData.Score
-- Check if target is in zone.
if ScoreZone:IsVec2InZone( TargetUnit:GetVec2() ) then if ScoreZone:IsVec2InZone( TargetUnit:GetVec2() ) then
Player.Score = Player.Score + Score Player.Score = Player.Score + Score
TargetDestroy.Score = TargetDestroy.Score + Score TargetDestroy.Score = TargetDestroy.Score + Score
MESSAGE MESSAGE
:NewType( self.DisplayMessagePrefix .. "Target destroyed in zone '" .. ScoreZone:GetName() .. "'." .. :NewType( self.DisplayMessagePrefix .. "Target destroyed in zone '" .. ScoreZone:GetName() .. "'." ..
"Player '" .. PlayerName .. "' receives an extra " .. Score .. " points! " .. "Player '" .. PlayerName .. "' receives an extra " .. Score .. " points! " ..
@@ -1434,8 +1338,6 @@ function SCORING:_EventOnDeadOrCrash( Event )
MESSAGE.Type.Information ) MESSAGE.Type.Information )
:ToAllIf( self:IfMessagesZone() and self:IfMessagesToAll() ) :ToAllIf( self:IfMessagesZone() and self:IfMessagesToAll() )
:ToCoalitionIf( InitCoalition, self:IfMessagesZone() and self:IfMessagesToCoalition() ) :ToCoalitionIf( InitCoalition, self:IfMessagesZone() and self:IfMessagesToCoalition() )
-- Write CSV.
self:ScoreCSV( PlayerName, TargetPlayerName, "DESTROY_SCORE", 1, Score, InitUnitName, InitUnitCoalition, InitUnitCategory, InitUnitType, TargetUnitName, TargetUnitCoalition, TargetUnitCategory, TargetUnitType ) self:ScoreCSV( PlayerName, TargetPlayerName, "DESTROY_SCORE", 1, Score, InitUnitName, InitUnitCoalition, InitUnitCategory, InitUnitType, TargetUnitName, TargetUnitCoalition, TargetUnitCategory, TargetUnitType )
Destroyed = true Destroyed = true
end end
@@ -1443,21 +1345,14 @@ function SCORING:_EventOnDeadOrCrash( Event )
end end
else else
---
-- Scenery Destroyed
---
-- Check if there are Zones where the destruction happened. -- Check if there are Zones where the destruction happened.
for ZoneName, ScoreZoneData in pairs( self.ScoringZones ) do for ZoneName, ScoreZoneData in pairs( self.ScoringZones ) do
self:F( { ScoringZone = ScoreZoneData } ) self:F( { ScoringZone = ScoreZoneData } )
local ScoreZone = ScoreZoneData.ScoreZone -- Core.Zone#ZONE_BASE local ScoreZone = ScoreZoneData.ScoreZone -- Core.Zone#ZONE_BASE
local Score = ScoreZoneData.Score local Score = ScoreZoneData.Score
if ScoreZone:IsVec2InZone( TargetUnit:GetVec2() ) then if ScoreZone:IsVec2InZone( TargetUnit:GetVec2() ) then
Player.Score = Player.Score + Score Player.Score = Player.Score + Score
TargetDestroy.Score = TargetDestroy.Score + Score TargetDestroy.Score = TargetDestroy.Score + Score
MESSAGE MESSAGE
:NewType( self.DisplayMessagePrefix .. "Scenery destroyed in zone '" .. ScoreZone:GetName() .. "'." .. :NewType( self.DisplayMessagePrefix .. "Scenery destroyed in zone '" .. ScoreZone:GetName() .. "'." ..
"Player '" .. PlayerName .. "' receives an extra " .. Score .. " points! " .. "Player '" .. PlayerName .. "' receives an extra " .. Score .. " points! " ..
@@ -1466,13 +1361,10 @@ function SCORING:_EventOnDeadOrCrash( Event )
) )
:ToAllIf( self:IfMessagesZone() and self:IfMessagesToAll() ) :ToAllIf( self:IfMessagesZone() and self:IfMessagesToAll() )
:ToCoalitionIf( InitCoalition, self:IfMessagesZone() and self:IfMessagesToCoalition() ) :ToCoalitionIf( InitCoalition, self:IfMessagesZone() and self:IfMessagesToCoalition() )
--Write CSV.
Destroyed = true Destroyed = true
self:ScoreCSV( PlayerName, "", "DESTROY_SCORE", 1, Score, InitUnitName, InitUnitCoalition, InitUnitCategory, InitUnitType, TargetUnitName, "", "Scenery", TargetUnitType ) self:ScoreCSV( PlayerName, "", "DESTROY_SCORE", 1, Score, InitUnitName, InitUnitCoalition, InitUnitCategory, InitUnitType, TargetUnitName, "", "Scenery", TargetUnitType )
end end
end end
end end
-- Delete now the hit cache if the target was destroyed. -- Delete now the hit cache if the target was destroyed.
@@ -1481,7 +1373,6 @@ function SCORING:_EventOnDeadOrCrash( Event )
if Destroyed then if Destroyed then
Player.Hit[TargetCategory][TargetUnitName].TimeStamp = 0 Player.Hit[TargetCategory][TargetUnitName].TimeStamp = 0
end end
end end
end end
end end
@@ -1498,8 +1389,7 @@ function SCORING:ReportDetailedPlayerHits( PlayerName )
local PlayerScore = 0 local PlayerScore = 0
local PlayerPenalty = 0 local PlayerPenalty = 0
local PlayerData = self.Players[PlayerName] --#SCORING.PlayerData local PlayerData = self.Players[PlayerName]
if PlayerData then -- This should normally not happen, but i'll test it anyway. if PlayerData then -- This should normally not happen, but i'll test it anyway.
self:T( "Score Player: " .. PlayerName ) self:T( "Score Player: " .. PlayerName )
@@ -1514,24 +1404,19 @@ function SCORING:ReportDetailedPlayerHits( PlayerName )
self:T( CategoryName ) self:T( CategoryName )
if PlayerData.Hit[CategoryID] then if PlayerData.Hit[CategoryID] then
self:T( "Hit scores exist for player " .. PlayerName ) self:T( "Hit scores exist for player " .. PlayerName )
local Score = 0 local Score = 0
local ScoreHit = 0 local ScoreHit = 0
local Penalty = 0 local Penalty = 0
local PenaltyHit = 0 local PenaltyHit = 0
for UnitName, UnitData in pairs( PlayerData.Hit[CategoryID] ) do for UnitName, UnitData in pairs( PlayerData.Hit[CategoryID] ) do
Score = Score + UnitData.Score Score = Score + UnitData.Score
ScoreHit = ScoreHit + UnitData.ScoreHit ScoreHit = ScoreHit + UnitData.ScoreHit
Penalty = Penalty + UnitData.Penalty Penalty = Penalty + UnitData.Penalty
PenaltyHit = UnitData.PenaltyHit PenaltyHit = UnitData.PenaltyHit
end end
local ScoreMessageHit = string.format( "%s:%d ", CategoryName, Score - Penalty ) local ScoreMessageHit = string.format( "%s:%d ", CategoryName, Score - Penalty )
self:T( ScoreMessageHit ) self:T( ScoreMessageHit )
ScoreMessageHits = ScoreMessageHits .. ScoreMessageHit ScoreMessageHits = ScoreMessageHits .. ScoreMessageHit
PlayerScore = PlayerScore + Score PlayerScore = PlayerScore + Score
PlayerPenalty = PlayerPenalty + Penalty PlayerPenalty = PlayerPenalty + Penalty
else else
@@ -1729,43 +1614,37 @@ function SCORING:ReportScoreGroupSummary( PlayerGroup )
if PlayerName then if PlayerName then
local Player=self.Players[PlayerName] --#SCORING.PlayerData local ReportHits, ScoreHits, PenaltyHits = self:ReportDetailedPlayerHits( PlayerName )
ReportHits = ReportHits ~= "" and "\n- " .. ReportHits or ReportHits
self:F( { ReportHits, ScoreHits, PenaltyHits } )
if Player then local ReportDestroys, ScoreDestroys, PenaltyDestroys = self:ReportDetailedPlayerDestroys( PlayerName )
ReportDestroys = ReportDestroys ~= "" and "\n- " .. ReportDestroys or ReportDestroys
self:F( { ReportDestroys, ScoreDestroys, PenaltyDestroys } )
local ReportHits, ScoreHits, PenaltyHits = self:ReportDetailedPlayerHits( PlayerName ) local ReportCoalitionChanges, ScoreCoalitionChanges, PenaltyCoalitionChanges = self:ReportDetailedPlayerCoalitionChanges( PlayerName )
ReportHits = ReportHits ~= "" and "\n- " .. ReportHits or ReportHits ReportCoalitionChanges = ReportCoalitionChanges ~= "" and "\n- " .. ReportCoalitionChanges or ReportCoalitionChanges
self:F( { ReportHits, ScoreHits, PenaltyHits } ) self:F( { ReportCoalitionChanges, ScoreCoalitionChanges, PenaltyCoalitionChanges } )
local ReportDestroys, ScoreDestroys, PenaltyDestroys = self:ReportDetailedPlayerDestroys( PlayerName ) local ReportGoals, ScoreGoals, PenaltyGoals = self:ReportDetailedPlayerGoals( PlayerName )
ReportDestroys = ReportDestroys ~= "" and "\n- " .. ReportDestroys or ReportDestroys ReportGoals = ReportGoals ~= "" and "\n- " .. ReportGoals or ReportGoals
self:F( { ReportDestroys, ScoreDestroys, PenaltyDestroys } ) self:F( { ReportGoals, ScoreGoals, PenaltyGoals } )
local ReportCoalitionChanges, ScoreCoalitionChanges, PenaltyCoalitionChanges = self:ReportDetailedPlayerCoalitionChanges( PlayerName ) local ReportMissions, ScoreMissions, PenaltyMissions = self:ReportDetailedPlayerMissions( PlayerName )
ReportCoalitionChanges = ReportCoalitionChanges ~= "" and "\n- " .. ReportCoalitionChanges or ReportCoalitionChanges ReportMissions = ReportMissions ~= "" and "\n- " .. ReportMissions or ReportMissions
self:F( { ReportCoalitionChanges, ScoreCoalitionChanges, PenaltyCoalitionChanges } ) self:F( { ReportMissions, ScoreMissions, PenaltyMissions } )
local ReportGoals, ScoreGoals, PenaltyGoals = self:ReportDetailedPlayerGoals( PlayerName ) local PlayerScore = ScoreHits + ScoreDestroys + ScoreCoalitionChanges + ScoreGoals + ScoreMissions
ReportGoals = ReportGoals ~= "" and "\n- " .. ReportGoals or ReportGoals local PlayerPenalty = PenaltyHits + PenaltyDestroys + PenaltyCoalitionChanges + PenaltyGoals + PenaltyMissions
self:F( { ReportGoals, ScoreGoals, PenaltyGoals } )
local ReportMissions, ScoreMissions, PenaltyMissions = self:ReportDetailedPlayerMissions( PlayerName ) PlayerMessage =
ReportMissions = ReportMissions ~= "" and "\n- " .. ReportMissions or ReportMissions string.format( "Player '%s' Score = %d ( %d Score, -%d Penalties )",
self:F( { ReportMissions, ScoreMissions, PenaltyMissions } ) PlayerName,
PlayerScore - PlayerPenalty,
local PlayerScore = Player.Score --ScoreHits + ScoreDestroys + ScoreCoalitionChanges + ScoreGoals + ScoreMissions PlayerScore,
local PlayerPenalty = Player.Penalty --PenaltyHits + PenaltyDestroys + PenaltyCoalitionChanges + ScoreGoals + PenaltyMissions PlayerPenalty
)
PlayerMessage = MESSAGE:NewType( PlayerMessage, MESSAGE.Type.Detailed ):ToGroup( PlayerGroup )
string.format( "Player '%s' Score = %d ( %d Score, -%d Penalties )",
PlayerName,
PlayerScore - PlayerPenalty,
PlayerScore,
PlayerPenalty
)
MESSAGE:NewType( PlayerMessage, MESSAGE.Type.Detailed ):ToGroup( PlayerGroup )
end
end end
end end
@@ -1787,47 +1666,42 @@ function SCORING:ReportScoreGroupDetailed( PlayerGroup )
if PlayerName then if PlayerName then
local Player=self.Players[PlayerName] --#SCORING.PlayerData local ReportHits, ScoreHits, PenaltyHits = self:ReportDetailedPlayerHits( PlayerName )
ReportHits = ReportHits ~= "" and "\n- " .. ReportHits or ReportHits
self:F( { ReportHits, ScoreHits, PenaltyHits } )
if Player then local ReportDestroys, ScoreDestroys, PenaltyDestroys = self:ReportDetailedPlayerDestroys( PlayerName )
ReportDestroys = ReportDestroys ~= "" and "\n- " .. ReportDestroys or ReportDestroys
self:F( { ReportDestroys, ScoreDestroys, PenaltyDestroys } )
local ReportHits, ScoreHits, PenaltyHits = self:ReportDetailedPlayerHits( PlayerName ) local ReportCoalitionChanges, ScoreCoalitionChanges, PenaltyCoalitionChanges = self:ReportDetailedPlayerCoalitionChanges( PlayerName )
ReportHits = ReportHits ~= "" and "\n- " .. ReportHits or ReportHits ReportCoalitionChanges = ReportCoalitionChanges ~= "" and "\n- " .. ReportCoalitionChanges or ReportCoalitionChanges
self:F( { ReportHits, ScoreHits, PenaltyHits } ) self:F( { ReportCoalitionChanges, ScoreCoalitionChanges, PenaltyCoalitionChanges } )
local ReportDestroys, ScoreDestroys, PenaltyDestroys = self:ReportDetailedPlayerDestroys( PlayerName ) local ReportGoals, ScoreGoals, PenaltyGoals = self:ReportDetailedPlayerGoals( PlayerName )
ReportDestroys = ReportDestroys ~= "" and "\n- " .. ReportDestroys or ReportDestroys ReportGoals = ReportGoals ~= "" and "\n- " .. ReportGoals or ReportGoals
self:F( { ReportDestroys, ScoreDestroys, PenaltyDestroys } ) self:F( { ReportGoals, ScoreGoals, PenaltyGoals } )
local ReportCoalitionChanges, ScoreCoalitionChanges, PenaltyCoalitionChanges = self:ReportDetailedPlayerCoalitionChanges( PlayerName ) local ReportMissions, ScoreMissions, PenaltyMissions = self:ReportDetailedPlayerMissions( PlayerName )
ReportCoalitionChanges = ReportCoalitionChanges ~= "" and "\n- " .. ReportCoalitionChanges or ReportCoalitionChanges ReportMissions = ReportMissions ~= "" and "\n- " .. ReportMissions or ReportMissions
self:F( { ReportCoalitionChanges, ScoreCoalitionChanges, PenaltyCoalitionChanges } ) self:F( { ReportMissions, ScoreMissions, PenaltyMissions } )
local ReportGoals, ScoreGoals, PenaltyGoals = self:ReportDetailedPlayerGoals( PlayerName ) local PlayerScore = ScoreHits + ScoreDestroys + ScoreCoalitionChanges + ScoreGoals + ScoreMissions
ReportGoals = ReportGoals ~= "" and "\n- " .. ReportGoals or ReportGoals local PlayerPenalty = PenaltyHits + PenaltyDestroys + PenaltyCoalitionChanges + ScoreGoals + PenaltyMissions
self:F( { ReportGoals, ScoreGoals, PenaltyGoals } )
local ReportMissions, ScoreMissions, PenaltyMissions = self:ReportDetailedPlayerMissions( PlayerName ) PlayerMessage =
ReportMissions = ReportMissions ~= "" and "\n- " .. ReportMissions or ReportMissions string.format( "Player '%s' Score = %d ( %d Score, -%d Penalties )%s%s%s%s%s",
self:F( { ReportMissions, ScoreMissions, PenaltyMissions } ) PlayerName,
PlayerScore - PlayerPenalty,
local PlayerScore = Player.Score --ScoreHits + ScoreDestroys + ScoreCoalitionChanges + ScoreGoals + ScoreMissions PlayerScore,
local PlayerPenalty = Player.Penalty --PenaltyHits + PenaltyDestroys + PenaltyCoalitionChanges + ScoreGoals + PenaltyMissions PlayerPenalty,
ReportHits,
PlayerMessage = ReportDestroys,
string.format( "Player '%s' Score = %d ( %d Score, -%d Penalties )%s%s%s%s%s", ReportCoalitionChanges,
PlayerName, ReportGoals,
PlayerScore - PlayerPenalty, ReportMissions
PlayerScore, )
PlayerPenalty, MESSAGE:NewType( PlayerMessage, MESSAGE.Type.Detailed ):ToGroup( PlayerGroup )
ReportHits,
ReportDestroys,
ReportCoalitionChanges,
ReportGoals,
ReportMissions
)
MESSAGE:NewType( PlayerMessage, MESSAGE.Type.Detailed ):ToGroup( PlayerGroup )
end
end end
end end
@@ -1848,91 +1722,83 @@ function SCORING:ReportScoreAllSummary( PlayerGroup )
if PlayerName then if PlayerName then
local Player=self.Players[PlayerName] --#SCORING.PlayerData local ReportHits, ScoreHits, PenaltyHits = self:ReportDetailedPlayerHits( PlayerName )
ReportHits = ReportHits ~= "" and "\n- " .. ReportHits or ReportHits
self:F( { ReportHits, ScoreHits, PenaltyHits } )
if Player then local ReportDestroys, ScoreDestroys, PenaltyDestroys = self:ReportDetailedPlayerDestroys( PlayerName )
ReportDestroys = ReportDestroys ~= "" and "\n- " .. ReportDestroys or ReportDestroys
self:F( { ReportDestroys, ScoreDestroys, PenaltyDestroys } )
local ReportHits, ScoreHits, PenaltyHits = self:ReportDetailedPlayerHits( PlayerName ) local ReportCoalitionChanges, ScoreCoalitionChanges, PenaltyCoalitionChanges = self:ReportDetailedPlayerCoalitionChanges( PlayerName )
ReportHits = ReportHits ~= "" and "\n- " .. ReportHits or ReportHits ReportCoalitionChanges = ReportCoalitionChanges ~= "" and "\n- " .. ReportCoalitionChanges or ReportCoalitionChanges
self:F( { ReportHits, ScoreHits, PenaltyHits } ) self:F( { ReportCoalitionChanges, ScoreCoalitionChanges, PenaltyCoalitionChanges } )
local ReportDestroys, ScoreDestroys, PenaltyDestroys = self:ReportDetailedPlayerDestroys( PlayerName ) local ReportGoals, ScoreGoals, PenaltyGoals = self:ReportDetailedPlayerGoals( PlayerName )
ReportDestroys = ReportDestroys ~= "" and "\n- " .. ReportDestroys or ReportDestroys ReportGoals = ReportGoals ~= "" and "\n- " .. ReportGoals or ReportGoals
self:F( { ReportDestroys, ScoreDestroys, PenaltyDestroys } ) self:F( { ReportGoals, ScoreGoals, PenaltyGoals } )
local ReportCoalitionChanges, ScoreCoalitionChanges, PenaltyCoalitionChanges = self:ReportDetailedPlayerCoalitionChanges( PlayerName ) local ReportMissions, ScoreMissions, PenaltyMissions = self:ReportDetailedPlayerMissions( PlayerName )
ReportCoalitionChanges = ReportCoalitionChanges ~= "" and "\n- " .. ReportCoalitionChanges or ReportCoalitionChanges ReportMissions = ReportMissions ~= "" and "\n- " .. ReportMissions or ReportMissions
self:F( { ReportCoalitionChanges, ScoreCoalitionChanges, PenaltyCoalitionChanges } ) self:F( { ReportMissions, ScoreMissions, PenaltyMissions } )
local ReportGoals, ScoreGoals, PenaltyGoals = self:ReportDetailedPlayerGoals( PlayerName ) local PlayerScore = ScoreHits + ScoreDestroys + ScoreCoalitionChanges + ScoreGoals + ScoreMissions
ReportGoals = ReportGoals ~= "" and "\n- " .. ReportGoals or ReportGoals local PlayerPenalty = PenaltyHits + PenaltyDestroys + PenaltyCoalitionChanges + ScoreGoals + PenaltyMissions
self:F( { ReportGoals, ScoreGoals, PenaltyGoals } )
local ReportMissions, ScoreMissions, PenaltyMissions = self:ReportDetailedPlayerMissions( PlayerName ) PlayerMessage =
ReportMissions = ReportMissions ~= "" and "\n- " .. ReportMissions or ReportMissions string.format( "Player '%s' Score = %d ( %d Score, -%d Penalties )",
self:F( { ReportMissions, ScoreMissions, PenaltyMissions } ) PlayerName,
PlayerScore - PlayerPenalty,
local PlayerScore = Player.Score --ScoreHits + ScoreDestroys + ScoreCoalitionChanges + ScoreGoals + ScoreMissions PlayerScore,
local PlayerPenalty = Player.Penalty --PenaltyHits + PenaltyDestroys + PenaltyCoalitionChanges + ScoreGoals + PenaltyMissions PlayerPenalty
)
PlayerMessage = MESSAGE:NewType( PlayerMessage, MESSAGE.Type.Overview ):ToGroup( PlayerGroup )
string.format( "Player '%s' Score = %d ( %d Score, -%d Penalties )",
PlayerName,
PlayerScore - PlayerPenalty,
PlayerScore,
PlayerPenalty
)
MESSAGE:NewType( PlayerMessage, MESSAGE.Type.Overview ):ToGroup( PlayerGroup )
end
end end
end end
end end
function SCORING:SecondsToClock(sSeconds)
local nSeconds = sSeconds
if nSeconds == 0 then
--return nil;
return "00:00:00";
else
nHours = string.format("%02.f", math.floor(nSeconds/3600));
nMins = string.format("%02.f", math.floor(nSeconds/60 - (nHours*60)));
nSecs = string.format("%02.f", math.floor(nSeconds - nHours*3600 - nMins *60));
return nHours..":"..nMins..":"..nSecs
end
end
--- Opens a score CSV file to log the scores. --- Opens a score CSV file to log the scores.
-- @param #SCORING self -- @param #SCORING self
-- @param #string ScoringCSV -- @param #string ScoringCSV
-- @param #string FileName Name of the csv file.
-- @return #SCORING self -- @return #SCORING self
-- @usage -- @usage
-- -- Open a new CSV file to log the scores of the game Gori Valley. Let the name of the CSV file begin with "Player Scores". -- -- Open a new CSV file to log the scores of the game Gori Valley. Let the name of the CSV file begin with "Player Scores".
-- ScoringObject = SCORING:New( "Gori Valley" ) -- ScoringObject = SCORING:New( "Gori Valley" )
-- ScoringObject:OpenCSV( "Player Scores" ) -- ScoringObject:OpenCSV( "Player Scores" )
function SCORING:OpenCSV( ScoringCSV, FileName ) function SCORING:OpenCSV( ScoringCSV )
self:F( ScoringCSV ) self:F( ScoringCSV )
if lfs and io and os then if lfs and io and os then
if ScoringCSV then if ScoringCSV then
self.ScoringCSV = ScoringCSV
local fdir = lfs.writedir() .. [[Logs\]] .. self.ScoringCSV .. " " .. os.date( "%Y-%m-%d %H-%M-%S" ) .. ".csv"
-- File name. self.CSVFile, self.err = io.open( fdir, "w+" )
local fdir = lfs.writedir() .. [[Logs\]] .. ScoringCSV .. " " .. os.date( "%Y-%m-%d %H-%M-%S" ) .. ".csv" if not self.CSVFile then
error( "Error: Cannot open CSV file in " .. lfs.writedir() )
if FileName then
fdir=lfs.writedir() .. [[Logs\]] .. FileName
end end
if UTILS.FileExists(fdir) then self.CSVFile:write( '"GameName","RunTime","Time","PlayerName","TargetPlayerName","ScoreType","PlayerUnitCoaltion","PlayerUnitCategory","PlayerUnitType","PlayerUnitName","TargetUnitCoalition","TargetUnitCategory","TargetUnitType","TargetUnitName","Times","Score"\n' )
self:LoadCSV(fdir)
self.CSVFile, self.err = io.open( fdir, "a+" )
if not self.CSVFile then
error( "Error: Cannot open CSV file in " .. lfs.writedir() )
end
else
self.CSVFile, self.err = io.open( fdir, "w+" )
if not self.CSVFile then
error( "Error: Cannot open CSV file in " .. lfs.writedir() )
end
self.CSVFile:write( '"GameName","RunTime","Time","PlayerName","TargetPlayerName","ScoreType","PlayerUnitCoaltion","PlayerUnitCategory","PlayerUnitType","PlayerUnitName","TargetUnitCoalition","TargetUnitCategory","TargetUnitType","TargetUnitName","Times","Score"\n' )
end
self.RunTime = os.date("%y-%m-%d_%H-%M-%S") self.RunTime = os.date("%y-%m-%d_%H-%M-%S")
else else
error( "A string containing the CSV file name must be given." ) error( "A string containing the CSV file name must be given." )
end end
else else
self:F( "The MissionScripting.lua file has not been changed to allow lfs, io and os modules to be used..." ) self:F( "The MissionScripting.lua file has not been changed to allow lfs, io and os modules to be used..." )
end end
@@ -1940,128 +1806,6 @@ function SCORING:OpenCSV( ScoringCSV, FileName )
end end
--- Load player data from file.
-- @param #SCORING self
-- @param #string filename File name containing player scoring data.
function SCORING:LoadCSV(filename)
--- Function that load data from a file.
local function _loadfile(filename)
local f=io.open(filename, "rb")
if f then
local data=f:read("*all")
f:close()
return data
else
self:E(self.id..string.format("ERROR: Could not load player results from file %s", tostring(filename)))
return nil
end
end
-- Info message.
local text=string.format("Loading player scoring from file %s", filename)
self:I(text)
-- Load asset data from file.
local data=_loadfile(filename)
if data then
-- Split by line break.
local results=UTILS.Split(data,"\n")
-- Remove first header line.
table.remove(results, 1)
-- Init player scores table.
self.CSVdata=self.CSVdata or {}
-- Loop over all lines.
for _,_result in pairs(results) do
-- Parameters are separated by commata.
local resultdata=UTILS.Split(_result, ",")
-- Grade table
local result={}
--'"GameName","RunTime","Time","PlayerName","TargetPlayerName","ScoreType","PlayerUnitCoaltion","PlayerUnitCategory","PlayerUnitType","PlayerUnitName","TargetUnitCoalition",
-- "TargetUnitCategory","TargetUnitType","TargetUnitName","Times","Score"\n'
local PlayerName=tostring(resultdata[4])
-- Results data.
result.GameName=tostring(resultdata[1])
result.RunTime=tostring(resultdata[2])
result.Time=tonumber(resultdata[3])
result.PlayerName=tostring(resultdata[4])
result.TargetPlayerName=tostring(resultdata[5])
result.ScoreType=tostring(resultdata[6])
result.PlayerUnitCoaltion=tostring(resultdata[7])
result.PlayerUnitCategory=tostring(resultdata[8])
result.PlayerUnitType=tostring(resultdata[9])
result.PlayerUnitName=tostring(resultdata[10])
result.TargetUnitCoalition=tostring(resultdata[11])
result.TargetUnitCategory=tostring(resultdata[12])
result.TargetUnitType=tostring(resultdata[13])
result.TargetUnitName=tostring(resultdata[14])
result.Times=tonumber(resultdata[15])
result.Score=tonumber(resultdata[16])
self:E(result.Score)
-- Create player array if necessary.
self.CSVdata[result.PlayerName]=self.CSVdata[result.PlayerName] or {}
-- Init player array if it does not exist.
if self.Players[PlayerName] == nil then
self.Players[PlayerName] = {}
self.Players[PlayerName].Hit = {}
self.Players[PlayerName].Destroy = {}
self.Players[PlayerName].Goals = {}
self.Players[PlayerName].Mission = {}
self.Players[PlayerName].HitPlayers = {}
self.Players[PlayerName].Score = 0
self.Players[PlayerName].Penalty = 0
self.Players[PlayerName].PenaltyCoalition = 0
self.Players[PlayerName].PenaltyWarning = 0
end
local Player=self.Players[PlayerName] --#SCORING.PlayerData
-- Restore player scores.
if result.ScoreType then
if result.ScoreType:find("PENALTY") then
-- Penalty
Player.Penalty=Player.Penalty+result.Score
-- Coalition change penalty.
if result.ScoreType:find("COALITION_PENALTY") then
Player.PenaltyCoalition=Player.PenaltyCoalition+1
end
end
if result.ScoreType:find("SCORE") then
Player.Score=Player.Score+result.Score
end
end
self:E(string.format("Player %s score = %d %d", PlayerName, Player.Score, self.Players[PlayerName].Score))
--self.Players[PlayerName].Score=self.Players[PlayerName].Score+result.Score
-- Add result to table.
table.insert(self.CSVdata[result.PlayerName], result)
end
end
end
--- Registers a score for a player. --- Registers a score for a player.
-- @param #SCORING self -- @param #SCORING self
-- @param #string PlayerName The name of the player. -- @param #string PlayerName The name of the player.
@@ -2079,17 +1823,11 @@ end
-- @param #string TargetUnitType The type of the target unit. -- @param #string TargetUnitType The type of the target unit.
-- @return #SCORING self -- @return #SCORING self
function SCORING:ScoreCSV( PlayerName, TargetPlayerName, ScoreType, ScoreTimes, ScoreAmount, PlayerUnitName, PlayerUnitCoalition, PlayerUnitCategory, PlayerUnitType, TargetUnitName, TargetUnitCoalition, TargetUnitCategory, TargetUnitType ) function SCORING:ScoreCSV( PlayerName, TargetPlayerName, ScoreType, ScoreTimes, ScoreAmount, PlayerUnitName, PlayerUnitCoalition, PlayerUnitCategory, PlayerUnitType, TargetUnitName, TargetUnitCoalition, TargetUnitCategory, TargetUnitType )
--write statistic information to file --write statistic information to file
--local ScoreTime = self:SecondsToClock( timer.getTime() ) local ScoreTime = self:SecondsToClock( timer.getTime() )
local ScoreTime = UTILS.SecondsToClock(timer.getAbsTime())
-- Player name
PlayerName = PlayerName:gsub( '"', '_' ) PlayerName = PlayerName:gsub( '"', '_' )
-- Target NAme TargetPlayerName = TargetPlayerName or ""
TargetPlayerName = TargetPlayerName or "n/a"
TargetPlayerName = TargetPlayerName:gsub( '"', '_' ) TargetPlayerName = TargetPlayerName:gsub( '"', '_' )
if PlayerUnitName and PlayerUnitName ~= '' then if PlayerUnitName and PlayerUnitName ~= '' then
@@ -2109,40 +1847,40 @@ function SCORING:ScoreCSV( PlayerName, TargetPlayerName, ScoreType, ScoreTimes,
PlayerUnitType = PlayerUnit:getTypeName() PlayerUnitType = PlayerUnit:getTypeName()
end end
else else
PlayerUnitName = 'n/a' PlayerUnitName = ''
PlayerUnitCategory = 'n/a' PlayerUnitCategory = ''
PlayerUnitCoalition = 'n/a' PlayerUnitCoalition = ''
PlayerUnitType = 'n/a' PlayerUnitType = ''
end end
else else
PlayerUnitName = 'n/a' PlayerUnitName = ''
PlayerUnitCategory = 'n/a' PlayerUnitCategory = ''
PlayerUnitCoalition = 'n/a' PlayerUnitCoalition = ''
PlayerUnitType = 'n/a' PlayerUnitType = ''
end end
TargetUnitCoalition = TargetUnitCoalition or "n/a" TargetUnitCoalition = TargetUnitCoalition or ""
TargetUnitCategory = TargetUnitCategory or "n/a" TargetUnitCategory = TargetUnitCategory or ""
TargetUnitType = TargetUnitType or "n/a" TargetUnitType = TargetUnitType or ""
TargetUnitName = TargetUnitName or "n/a" TargetUnitName = TargetUnitName or ""
if lfs and io and os then if lfs and io and os then
self.CSVFile:write( self.CSVFile:write(
'' .. self.GameName .. '' .. ',' .. '"' .. self.GameName .. '"' .. ',' ..
'' .. self.RunTime .. '' .. ',' .. '"' .. self.RunTime .. '"' .. ',' ..
'' .. ScoreTime .. '' .. ',' .. '' .. ScoreTime .. '' .. ',' ..
'' .. PlayerName .. '' .. ',' .. '"' .. PlayerName .. '"' .. ',' ..
'' .. TargetPlayerName .. '' .. ',' .. '"' .. TargetPlayerName .. '"' .. ',' ..
'' .. ScoreType .. '' .. ',' .. '"' .. ScoreType .. '"' .. ',' ..
'' .. PlayerUnitCoalition .. '' .. ',' .. '"' .. PlayerUnitCoalition .. '"' .. ',' ..
'' .. PlayerUnitCategory .. '' .. ',' .. '"' .. PlayerUnitCategory .. '"' .. ',' ..
'' .. PlayerUnitType .. '' .. ',' .. '"' .. PlayerUnitType .. '"' .. ',' ..
'' .. PlayerUnitName .. '' .. ',' .. '"' .. PlayerUnitName .. '"' .. ',' ..
'' .. TargetUnitCoalition .. '' .. ',' .. '"' .. TargetUnitCoalition .. '"' .. ',' ..
'' .. TargetUnitCategory .. '' .. ',' .. '"' .. TargetUnitCategory .. '"' .. ',' ..
'' .. TargetUnitType .. '' .. ',' .. '"' .. TargetUnitType .. '"' .. ',' ..
'' .. TargetUnitName .. '' .. ',' .. '"' .. TargetUnitName .. '"' .. ',' ..
'' .. ScoreTimes .. '' .. ',' .. '' .. ScoreTimes .. '' .. ',' ..
'' .. ScoreAmount '' .. ScoreAmount
) )
@@ -2150,10 +1888,10 @@ function SCORING:ScoreCSV( PlayerName, TargetPlayerName, ScoreType, ScoreTimes,
end end
end end
--- Close csv file.
-- @param #SCORING self
function SCORING:CloseCSV() function SCORING:CloseCSV()
if lfs and io and os then if lfs and io and os then
self.CSVFile:close() self.CSVFile:close()
end end
end end