Skip to content

Commit

Permalink
[Nachrichten] automatische Entfernung abgenutzter Nachrichten ueberar…
Browse files Browse the repository at this point in the history
…beitet. Idee: Helmut

Vorher: Nach 2 Tagen (links) oder 3 Tagen (rechts)

Nun: Nach 24h oder wenn <5% Aktualitaet (links) bzw. nach 36h oder wenn <0.1% Aktualitaet (rechts)
  • Loading branch information
GWRon committed Aug 23, 2016
1 parent 41b1bb7 commit d12928f
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 41 deletions.
4 changes: 2 additions & 2 deletions source/game.newsagency.bmx
Expand Up @@ -651,8 +651,8 @@ Type TNewsAgency

'quality and price are based on the movies data
'quality of movie news never can reach quality of "real" news
'so cut them to a specific range (0-0.75)
local quality:Float = 0.75*licence.GetData().review
'so cut them to a specific range (0.10 - 0.80)
local quality:Float = 0.1 + 0.70*licence.GetData().review
'if outcome is less than 50%, it subtracts the price, else it increases
local priceModifier:Float = 1.0 + 0.2 * (licence.GetData().outcome - 0.5)
Local NewsEvent:TNewsEvent = new TNewsEvent.Init("", localizeTitle, localizeDescription, TVTNewsGenre.SHOWBIZ, quality, null, TVTNewsType.InitialNewsByInGameEvent)
Expand Down
91 changes: 52 additions & 39 deletions source/main.bmx
Expand Up @@ -4998,6 +4998,10 @@ Type GameEvents

'things happening each hour
Function OnHour:Int(triggerEvent:TEventBase)
local time:Long = triggerEvent.GetData().GetLong("time",-1)
Local day:Int = GetWorldTime().GetDay(time)
Local hour:Int = GetWorldTime().GetHour(time)

'=== REMOVE ENDED NEWSEVENTS ===
'newsevents might have a "happenedEndTime" indicating that
'the event is only a temporary one (eg. storm warning)
Expand Down Expand Up @@ -5026,6 +5030,54 @@ Type GameEvents
EndIf
Next
endrem


'=== REMOVE OLD NEWS AND NEWSEVENTS ===
'news and newsevents both have a "happenedTime" but they must
'not be the same (multiple news with the same event but happened
'to different times)
Local hoursToKeep:Int
Local minTopicalityToKeep:Float

'remove old news from the all player plans and collections
For Local pBase:TPlayerBase = EachIn GetPlayerBaseCollection().players
local p:TPlayer = TPlayer(pBase)
if not p then continue

'COLLECTION
'news could stay there for 2 days (including today)
hoursToKeep = 24
minTopicalityToKeep = 0.05

'loop through a copy to avoid concurrent modification
For Local news:TNews = EachIn p.GetProgrammeCollection().news.Copy()
If hour - GetWorldTime().GetHour(news.GetHappenedTime()) > hoursToKeep
p.GetProgrammeCollection().RemoveNews(news)
elseif news.newsevent.GetTopicality() < minTopicalityToKeep
p.GetProgrammeCollection().RemoveNews(news)
EndIf
Next

'PLAN
'news could get send a bit longer
hoursToKeep = 36
minTopicalityToKeep = 0.01
'no need to copy the array because it has a fixed length
For Local news:TNews = EachIn p.GetProgrammePlan().news
If hour - GetWorldTime().GetHour(news.GetHappenedTime()) > hoursToKeep
p.GetProgrammePlan().RemoveNewsByGUID(news.GetGUID(), False)
elseif news.newsevent.GetTopicality() < minTopicalityToKeep
p.GetProgrammePlan().RemoveNewsByGUID(news.GetGUID(), False)
EndIf
Next
Next

'NEWSEVENTS
'remove old news events - wait a day more than "plan time"
'this also gets rid of "one time" news events which should
'have been "triggered" then
local daysToKeep:int = int(ceil((2 * hoursToKeep)/48.0))
GetNewsEventCollection().RemoveOutdatedNewsEvents(daysToKeep)
Next
'remove from collection (reuse if possible)
GetNewsEventCollection().RemoveEndedNewsEvents()
Expand Down Expand Up @@ -5105,45 +5157,6 @@ Type GameEvents
TLogger.Log("OnDay Financials", s, LOG_DEBUG)
Next
Next

'=== REMOVE OLD NEWS AND NEWSEVENTS ===
'news and newsevents both have a "happenedTime" but they must
'not be the same (multiple news with the same event but happened
'to different times)
Local daysToKeep:Int = 2

'remove old news from the all player plans and collections
For Local pBase:TPlayerBase = EachIn GetPlayerBaseCollection().players
local p:TPlayer = TPlayer(pBase)
if not p then continue

'COLLECTION
'news could stay there for 2 days (including today)
daysToKeep = 2
'loop through a copy to avoid concurrent modification
For Local news:TNews = EachIn p.GetProgrammeCollection().news.Copy()
If day - GetWorldTime().GetDay(news.GetHappenedTime()) >= daysToKeep
p.GetProgrammeCollection().RemoveNews(news)
EndIf
Next

'PLAN
'news could get send a day longer (3 days incl. today)
daysToKeep = 3
'no need to copy the array because it has a fixed length
For Local news:TNews = EachIn p.GetProgrammePlan().news
If day - GetWorldTime().GetDay(news.GetHappenedTime()) >= daysToKeep
p.GetProgrammePlan().RemoveNewsByGUID(news.GetGUID(), False)
EndIf
Next
Next

'NEWSEVENTS
'remove old news events - wait a day more than "plan time"
'this also gets rid of "one time" news events which should
'have been "triggered" then
daysToKeep = 4
GetNewsEventCollection().RemoveOutdatedNewsEvents(daysToKeep)
EndIf

Return True
Expand Down

0 comments on commit d12928f

Please sign in to comment.