mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
SCORING new functions addons.
This commit is contained in:
@@ -1,4 +1,16 @@
|
||||
--- Scoring system for MOOSE.
|
||||
--- Single-Player:**Yes** / Multi-Player:**Yes** / Core:**Yes** -- **Administer the scoring of player achievements,
|
||||
-- and create a CSV file logging the scoring events for use at team or squadron websites.**
|
||||
--
|
||||
-- -- 
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- # 1) @{Scoring#SCORING} class, extends @{Base#BASE}
|
||||
--
|
||||
-- The @{#SCORING} class administers the scoring of player achievements,
|
||||
-- and creates a CSV file logging the scoring events for use at team or squadron websites.
|
||||
-- In other words, use AI_BALANCER to simulate human behaviour by spawning in replacement AI in multi player missions.
|
||||
--
|
||||
-- This scoring class calculates the hits and kills that players make within a simulation session.
|
||||
-- Scoring is calculated using a defined algorithm.
|
||||
-- With a small change in MissionScripting.lua, the scoring can also be logged in a CSV file, that can then be uploaded
|
||||
@@ -56,7 +68,7 @@ function SCORING:New( GameName )
|
||||
self:HandleEvent( EVENTS.Hit, self._EventOnHit )
|
||||
|
||||
--self.SchedulerId = routines.scheduleFunction( SCORING._FollowPlayersScheduled, { self }, 0, 5 )
|
||||
self.SchedulerId = SCHEDULER:New( self, self._FollowPlayersScheduled, {}, 0, 5 )
|
||||
--self.SchedulerId = SCHEDULER:New( self, self._FollowPlayersScheduled, {}, 0, 5 )
|
||||
|
||||
self:ScoreMenu()
|
||||
|
||||
@@ -101,16 +113,18 @@ end
|
||||
|
||||
|
||||
--- Add a new player entering a Unit.
|
||||
-- @param #SCORING self
|
||||
-- @param Wrapper.Unit#UNIT UnitData
|
||||
function SCORING:_AddPlayerFromUnit( UnitData )
|
||||
self:F( UnitData )
|
||||
|
||||
if UnitData and UnitData:isExist() then
|
||||
local UnitName = UnitData:getName()
|
||||
local PlayerName = UnitData:getPlayerName()
|
||||
local UnitDesc = UnitData:getDesc()
|
||||
if UnitData:IsAlive() then
|
||||
local UnitName = UnitData:GetName()
|
||||
local PlayerName = UnitData:GetPlayerName()
|
||||
local UnitDesc = UnitData:GetDesc()
|
||||
local UnitCategory = UnitDesc.category
|
||||
local UnitCoalition = UnitData:getCoalition()
|
||||
local UnitTypeName = UnitData:getTypeName()
|
||||
local UnitCoalition = UnitData:GetCoalition()
|
||||
local UnitTypeName = UnitData:GetTypeName()
|
||||
|
||||
self:T( { PlayerName, UnitName, UnitCategory, UnitCoalition, UnitTypeName } )
|
||||
|
||||
@@ -149,6 +163,7 @@ function SCORING:_AddPlayerFromUnit( UnitData )
|
||||
self.Players[PlayerName].UnitCoalition = UnitCoalition
|
||||
self.Players[PlayerName].UnitCategory = UnitCategory
|
||||
self.Players[PlayerName].UnitType = UnitTypeName
|
||||
self.Players[PlayerName].UNIT = UnitData
|
||||
|
||||
if self.Players[PlayerName].Penalty > 100 then
|
||||
if self.Players[PlayerName].PenaltyWarning < 1 then
|
||||
@@ -160,7 +175,7 @@ function SCORING:_AddPlayerFromUnit( UnitData )
|
||||
end
|
||||
|
||||
if self.Players[PlayerName].Penalty > 150 then
|
||||
ClientGroup = GROUP:NewFromDCSUnit( UnitData )
|
||||
local ClientGroup = GROUP:NewFromDCSUnit( UnitData )
|
||||
ClientGroup:Destroy()
|
||||
MESSAGE:New( "Player '" .. PlayerName .. "' committed FRATRICIDE, he will be COURT MARTIALED and is DISMISSED from this mission!",
|
||||
10
|
||||
@@ -246,6 +261,7 @@ function SCORING:_EventOnHit( Event )
|
||||
self:F( { Event } )
|
||||
|
||||
local InitUnit = nil
|
||||
local InitUNIT = nil
|
||||
local InitUnitName = ""
|
||||
local InitGroup = nil
|
||||
local InitGroupName = ""
|
||||
@@ -259,6 +275,7 @@ function SCORING:_EventOnHit( Event )
|
||||
local InitUnitType = nil
|
||||
|
||||
local TargetUnit = nil
|
||||
local TargetUNIT = nil
|
||||
local TargetUnitName = ""
|
||||
local TargetGroup = nil
|
||||
local TargetGroupName = ""
|
||||
@@ -274,10 +291,11 @@ function SCORING:_EventOnHit( Event )
|
||||
if Event.IniDCSUnit then
|
||||
|
||||
InitUnit = Event.IniDCSUnit
|
||||
InitUNIT = Event.IniUnit
|
||||
InitUnitName = Event.IniDCSUnitName
|
||||
InitGroup = Event.IniDCSGroup
|
||||
InitGroupName = Event.IniDCSGroupName
|
||||
InitPlayerName = Event.IniPlayerName or ""
|
||||
InitPlayerName = Event.IniPlayerName
|
||||
|
||||
InitCoalition = InitUnit:getCoalition()
|
||||
--TODO: Workaround Client DCS Bug
|
||||
@@ -296,10 +314,11 @@ function SCORING:_EventOnHit( Event )
|
||||
if Event.TgtDCSUnit then
|
||||
|
||||
TargetUnit = Event.TgtDCSUnit
|
||||
TargetUNIT = Event.TgtUnit
|
||||
TargetUnitName = Event.TgtDCSUnitName
|
||||
TargetGroup = Event.TgtDCSGroup
|
||||
TargetGroupName = Event.TgtDCSGroupName
|
||||
TargetPlayerName = Event.TgtPlayerName or ""
|
||||
TargetPlayerName = Event.TgtPlayerName
|
||||
|
||||
TargetCoalition = TargetUnit:getCoalition()
|
||||
--TODO: Workaround Client DCS Bug
|
||||
@@ -315,10 +334,10 @@ function SCORING:_EventOnHit( Event )
|
||||
end
|
||||
|
||||
if InitPlayerName ~= nil then -- It is a player that is hitting something
|
||||
self:_AddPlayerFromUnit( InitUnit )
|
||||
self:_AddPlayerFromUnit( InitUNIT )
|
||||
if self.Players[InitPlayerName] then -- This should normally not happen, but i'll test it anyway.
|
||||
if TargetPlayerName ~= nil then -- It is a player hitting another player ...
|
||||
self:_AddPlayerFromUnit( TargetUnit )
|
||||
self:_AddPlayerFromUnit( TargetUNIT )
|
||||
end
|
||||
|
||||
self:T( "Hitting Something" )
|
||||
@@ -341,51 +360,58 @@ function SCORING:_EventOnHit( Event )
|
||||
PlayerHit.Penalty = PlayerHit.Penalty or 0
|
||||
PlayerHit.ScoreHit = PlayerHit.ScoreHit or 0
|
||||
PlayerHit.PenaltyHit = PlayerHit.PenaltyHit or 0
|
||||
PlayerHit.TimeStamp = PlayerHit.TimeStamp or 0
|
||||
PlayerHit.UNIT = PlayerHit.UNIT or TargetUNIT
|
||||
|
||||
-- Only grant hit scores if there was more than one second between the last hit.
|
||||
if timer.getTime() - PlayerHit.TimeStamp > 1 then
|
||||
PlayerHit.TimeStamp = timer.getTime()
|
||||
|
||||
if TargetPlayerName ~= nil then -- It is a player hitting another player ...
|
||||
|
||||
-- Ensure there is a Player to Player hit reference table.
|
||||
Player.HitPlayers[TargetPlayerName] = true
|
||||
end
|
||||
|
||||
local Score = 0
|
||||
if InitCoalition == TargetCoalition then
|
||||
Player.Penalty = Player.Penalty + 10
|
||||
PlayerHit.Penalty = PlayerHit.Penalty + 10
|
||||
PlayerHit.PenaltyHit = PlayerHit.PenaltyHit + 1
|
||||
|
||||
if TargetPlayerName ~= nil then -- It is a player hitting another player ...
|
||||
MESSAGE:New( "Player '" .. InitPlayerName .. "' hit friendly player '" .. TargetPlayerName .. "' " .. TargetUnitCategory .. " ( " .. TargetType .. " ) " ..
|
||||
PlayerHit.PenaltyHit .. " times. Penalty: -" .. PlayerHit.Penalty ..
|
||||
". Score Total:" .. Player.Score - Player.Penalty,
|
||||
2
|
||||
):ToAll()
|
||||
else
|
||||
MESSAGE:New( "Player '" .. InitPlayerName .. "' hit a friendly " .. TargetUnitCategory .. " ( " .. TargetType .. " ) " ..
|
||||
PlayerHit.PenaltyHit .. " times. Penalty: -" .. PlayerHit.Penalty ..
|
||||
". Score Total:" .. Player.Score - Player.Penalty,
|
||||
2
|
||||
):ToAll()
|
||||
|
||||
-- Ensure there is a Player to Player hit reference table.
|
||||
Player.HitPlayers[TargetPlayerName] = true
|
||||
end
|
||||
self:ScoreCSV( InitPlayerName, "HIT_PENALTY", 1, -25, InitUnitName, InitUnitCoalition, InitUnitCategory, InitUnitType, TargetUnitName, TargetUnitCoalition, TargetUnitCategory, TargetUnitType )
|
||||
else
|
||||
Player.Score = Player.Score + 1
|
||||
PlayerHit.Score = PlayerHit.Score + 1
|
||||
PlayerHit.ScoreHit = PlayerHit.ScoreHit + 1
|
||||
if TargetPlayerName ~= nil then -- It is a player hitting another player ...
|
||||
MESSAGE:New( "Player '" .. InitPlayerName .. "' hit enemy player '" .. TargetPlayerName .. "' " .. TargetUnitCategory .. " ( " .. TargetType .. " ) " ..
|
||||
PlayerHit.ScoreHit .. " times. Score: " .. PlayerHit.Score ..
|
||||
". Score Total:" .. Player.Score - Player.Penalty,
|
||||
2
|
||||
):ToAll()
|
||||
|
||||
local Score = 0
|
||||
if InitCoalition == TargetCoalition then
|
||||
Player.Penalty = Player.Penalty + 10
|
||||
PlayerHit.Penalty = PlayerHit.Penalty + 10
|
||||
PlayerHit.PenaltyHit = PlayerHit.PenaltyHit + 1
|
||||
|
||||
if TargetPlayerName ~= nil then -- It is a player hitting another player ...
|
||||
MESSAGE:New( "Player '" .. InitPlayerName .. "' hit friendly player '" .. TargetPlayerName .. "' " .. TargetUnitCategory .. " ( " .. TargetType .. " ) " ..
|
||||
PlayerHit.PenaltyHit .. " times. Penalty: -" .. PlayerHit.Penalty ..
|
||||
". Score Total:" .. Player.Score - Player.Penalty,
|
||||
2
|
||||
):ToAll()
|
||||
else
|
||||
MESSAGE:New( "Player '" .. InitPlayerName .. "' hit a friendly " .. TargetUnitCategory .. " ( " .. TargetType .. " ) " ..
|
||||
PlayerHit.PenaltyHit .. " times. Penalty: -" .. PlayerHit.Penalty ..
|
||||
". Score Total:" .. Player.Score - Player.Penalty,
|
||||
2
|
||||
):ToAll()
|
||||
end
|
||||
self:ScoreCSV( InitPlayerName, "HIT_PENALTY", 1, -25, InitUnitName, InitUnitCoalition, InitUnitCategory, InitUnitType, TargetUnitName, TargetUnitCoalition, TargetUnitCategory, TargetUnitType )
|
||||
else
|
||||
MESSAGE:New( "Player '" .. InitPlayerName .. "' hit an enemy " .. TargetUnitCategory .. " ( " .. TargetType .. " ) " ..
|
||||
PlayerHit.ScoreHit .. " times. Score: " .. PlayerHit.Score ..
|
||||
". Score Total:" .. Player.Score - Player.Penalty,
|
||||
2
|
||||
):ToAll()
|
||||
Player.Score = Player.Score + 1
|
||||
PlayerHit.Score = PlayerHit.Score + 1
|
||||
PlayerHit.ScoreHit = PlayerHit.ScoreHit + 1
|
||||
if TargetPlayerName ~= nil then -- It is a player hitting another player ...
|
||||
MESSAGE:New( "Player '" .. InitPlayerName .. "' hit enemy player '" .. TargetPlayerName .. "' " .. TargetUnitCategory .. " ( " .. TargetType .. " ) " ..
|
||||
PlayerHit.ScoreHit .. " times. Score: " .. PlayerHit.Score ..
|
||||
". Score Total:" .. Player.Score - Player.Penalty,
|
||||
2
|
||||
):ToAll()
|
||||
else
|
||||
MESSAGE:New( "Player '" .. InitPlayerName .. "' hit an enemy " .. TargetUnitCategory .. " ( " .. TargetType .. " ) " ..
|
||||
PlayerHit.ScoreHit .. " times. Score: " .. PlayerHit.Score ..
|
||||
". Score Total:" .. Player.Score - Player.Penalty,
|
||||
2
|
||||
):ToAll()
|
||||
end
|
||||
self:ScoreCSV( InitPlayerName, "HIT_SCORE", 1, 1, InitUnitName, InitUnitCoalition, InitUnitCategory, InitUnitType, TargetUnitName, TargetUnitCoalition, TargetUnitCategory, TargetUnitType )
|
||||
end
|
||||
self:ScoreCSV( InitPlayerName, "HIT_SCORE", 1, 1, InitUnitName, InitUnitCoalition, InitUnitCategory, InitUnitType, TargetUnitName, TargetUnitCoalition, TargetUnitCategory, TargetUnitType )
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -418,7 +444,7 @@ function SCORING:_EventOnDeadOrCrash( Event )
|
||||
TargetUnitName = Event.IniDCSUnitName
|
||||
TargetGroup = Event.IniDCSGroup
|
||||
TargetGroupName = Event.IniDCSGroupName
|
||||
TargetPlayerName = Event.IniPlayerName or ""
|
||||
TargetPlayerName = Event.IniPlayerName
|
||||
|
||||
TargetCoalition = TargetUnit:getCoalition()
|
||||
--TargetCategory = TargetUnit:getCategory()
|
||||
@@ -462,10 +488,14 @@ function SCORING:_EventOnDeadOrCrash( Event )
|
||||
PlayerKill.ScoreKill = PlayerKill.ScoreKill or 0
|
||||
PlayerKill.Penalty = PlayerKill.Penalty or 0
|
||||
PlayerKill.PenaltyKill = PlayerKill.PenaltyKill or 0
|
||||
PlayerKill.UNIT = PlayerKill.UNIT or Player.Hit[TargetCategory][TargetUnitName].UNIT
|
||||
|
||||
if InitCoalition == TargetCoalition then
|
||||
Player.Penalty = Player.Penalty + 25
|
||||
PlayerKill.Penalty = PlayerKill.Penalty + 25
|
||||
local ThreatLevelTarget = PlayerKill.UNIT:GetThreatLevel()
|
||||
local ThreatLevelPlayer = Player.UNIT:GetThreatLevel()
|
||||
local ThreatLevel = ThreatLevelTarget / ThreatLevelPlayer * 10
|
||||
Player.Penalty = Player.Penalty + ThreatLevel * 4
|
||||
PlayerKill.Penalty = PlayerKill.Penalty + ThreatLevel * 4
|
||||
PlayerKill.PenaltyKill = PlayerKill.PenaltyKill + 1
|
||||
|
||||
if Player.HitPlayers[TargetPlayerName] then -- A player killed another player
|
||||
@@ -481,8 +511,11 @@ function SCORING:_EventOnDeadOrCrash( Event )
|
||||
end
|
||||
self:ScoreCSV( PlayerName, "KILL_PENALTY", 1, -125, InitUnitName, InitUnitCoalition, InitUnitCategory, InitUnitType, TargetUnitName, TargetUnitCoalition, TargetUnitCategory, TargetUnitType )
|
||||
else
|
||||
Player.Score = Player.Score + 10
|
||||
PlayerKill.Score = PlayerKill.Score + 10
|
||||
local ThreatLevelTarget = PlayerKill.UNIT:GetThreatLevel()
|
||||
local ThreatLevelPlayer = Player.UNIT:GetThreatLevel()
|
||||
local ThreatLevel = ThreatLevelTarget / ThreatLevelPlayer * 10
|
||||
Player.Score = Player.Score + ThreatLevel
|
||||
PlayerKill.Score = PlayerKill.Score + ThreatLevel
|
||||
PlayerKill.ScoreKill = PlayerKill.ScoreKill + 1
|
||||
if Player.HitPlayers[TargetPlayerName] then -- A player killed another player
|
||||
MESSAGE:New( "Player '" .. PlayerName .. "' killed enemy player '" .. TargetPlayerName .. "' " .. TargetUnitCategory .. " ( " .. TargetType .. " ) " ..
|
||||
|
||||
Reference in New Issue
Block a user