Skip to content

Commit a1ebeca

Browse files
author
=
committed
pre-combines version
1 parent 3691b2f commit a1ebeca

File tree

3 files changed

+183
-88
lines changed

3 files changed

+183
-88
lines changed

endOfMatchProcessing.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ func endOfMatchProcessing(game *game) {
8787
game.totalPlayerStats[steam].suppDamage += player.suppDamage
8888
game.totalPlayerStats[steam].suppRounds += player.suppRounds
8989
game.totalPlayerStats[steam].rwk += player.rwk
90+
game.totalPlayerStats[steam].mip += player.mip
9091

9192
if player.side == 2 {
9293
game.totalPlayerStats[steam].winPointsNormalizer += game.rounds[i].initTerroristCount
@@ -103,6 +104,10 @@ func endOfMatchProcessing(game *game) {
103104
game.totalPlayerStats[steam].tWinPointsNormalizer += game.rounds[i].initTerroristCount
104105
game.totalPlayerStats[steam].tRounds += 1
105106
game.totalPlayerStats[steam].tRF += player.RF
107+
game.totalPlayerStats[steam].lurkRounds += player.lurkRounds
108+
if player.lurkRounds != 0 {
109+
game.totalPlayerStats[steam].wlp += player.winPoints
110+
}
106111

107112
game.rounds[i].teamStats[player.teamClanName].tWinPoints += player.winPoints
108113
game.rounds[i].teamStats[player.teamClanName].tImpactPoints += player.impactPoints
@@ -236,7 +241,7 @@ func calculateDerivedFields(game *game) {
236241
ctAdrAvg /= float64(ctRoundNormalizer)
237242

238243
for _, player := range game.totalPlayerStats {
239-
openingFactor := (float64(player.ok-player.ol) / 13.0) + 1
244+
openingFactor := (float64(player.ok-player.ol) / 13.0) + 1 //move from 13 to (rounds / 5)
240245
playerIPR := player.impactPoints / float64(player.rounds)
241246
playerWPR := player.winPoints / float64(player.rounds)
242247

main.go

+165-87
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ package main
33
import (
44
//"bufio"
55
"fmt"
6+
"io/ioutil"
67
"math"
78
"os"
9+
"path/filepath"
810
"strconv"
911
"strings"
10-
"io/ioutil"
11-
"path/filepath"
1212

1313
dem "github.com/markus-wa/demoinfocs-golang/v2/pkg/demoinfocs"
1414
common "github.com/markus-wa/demoinfocs-golang/v2/pkg/demoinfocs/common"
@@ -82,6 +82,7 @@ type flag struct {
8282
hasGameStarted bool
8383
isGameLive bool
8484
isGameOver bool
85+
inRound bool
8586
prePlant bool
8687
postPlant bool
8788
postWinCon bool
@@ -90,14 +91,16 @@ type flag struct {
9091
roundIntegrityEndOfficial int
9192

9293
//for the round (gets reset on a new round) maybe should be in a new struct
93-
tAlive int
94-
ctAlive int
95-
tMoney bool
96-
tClutchVal int
97-
ctClutchVal int
98-
tClutchSteam uint64
99-
ctClutchSteam uint64
100-
openingKill bool
94+
tAlive int
95+
ctAlive int
96+
tMoney bool
97+
tClutchVal int
98+
ctClutchVal int
99+
tClutchSteam uint64
100+
ctClutchSteam uint64
101+
openingKill bool
102+
lastTickProcessed int
103+
ticksProcessed int
101104
}
102105

103106
type team struct {
@@ -165,50 +168,56 @@ type playerStats struct {
165168
rounds int
166169
//playerPoints float32
167170
//teamPoints float32
168-
damage int
169-
kills uint8
170-
assists uint8
171-
deaths uint8
172-
deathTick int
173-
deathPlacement float64
174-
ticksAlive int
175-
trades int
176-
traded int
177-
ok int
178-
ol int
179-
cl_1 int
180-
cl_2 int
181-
cl_3 int
182-
cl_4 int
183-
cl_5 int
184-
_2k int
185-
_3k int
186-
_4k int
187-
_5k int
188-
nadeDmg int
189-
infernoDmg int
190-
utilDmg int
191-
ef int
192-
fAss int
193-
enemyFlashTime float64
194-
hs int
195-
kastRounds float64
196-
saves int
197-
entries int
198-
killPoints float64
199-
impactPoints float64
200-
winPoints float64
201-
awpKills int
202-
RF int
203-
RA int
204-
nadesThrown int
205-
firesThrown int
206-
flashThrown int
207-
smokeThrown int
208-
damageTaken int
209-
suppRounds int
210-
suppDamage int
211-
rwk int
171+
damage int
172+
kills uint8
173+
assists uint8
174+
deaths uint8
175+
deathTick int
176+
deathPlacement float64
177+
ticksAlive int
178+
trades int
179+
traded int
180+
ok int
181+
ol int
182+
cl_1 int
183+
cl_2 int
184+
cl_3 int
185+
cl_4 int
186+
cl_5 int
187+
_2k int
188+
_3k int
189+
_4k int
190+
_5k int
191+
nadeDmg int
192+
infernoDmg int
193+
utilDmg int
194+
ef int
195+
fAss int
196+
enemyFlashTime float64
197+
hs int
198+
kastRounds float64
199+
saves int
200+
entries int
201+
killPoints float64
202+
impactPoints float64
203+
winPoints float64
204+
awpKills int
205+
RF int
206+
RA int
207+
nadesThrown int
208+
firesThrown int
209+
flashThrown int
210+
smokeThrown int
211+
damageTaken int
212+
suppRounds int
213+
suppDamage int
214+
lurkerBlips int
215+
distanceToTeammates int
216+
lurkRounds int
217+
wlp float64
218+
mip float64
219+
220+
rwk int
212221

213222
//derived
214223
utilThrown int
@@ -271,18 +280,18 @@ type playerStats struct {
271280
}
272281

273282
func main() {
274-
input_dir := "in"
275-
files, _ := ioutil.ReadDir(input_dir)
276-
277-
for _, file := range files {
278-
filename := file.Name()
279-
if strings.HasSuffix(filename, ".dem") {
280-
fmt.Println("processing", file.Name())
281-
processDemo(filepath.Join(input_dir, filename))
282-
}
283-
}
284-
285-
var input string
283+
input_dir := "in"
284+
files, _ := ioutil.ReadDir(input_dir)
285+
286+
for _, file := range files {
287+
filename := file.Name()
288+
if strings.HasSuffix(filename, ".dem") {
289+
fmt.Println("processing", file.Name())
290+
go processDemo(filepath.Join(input_dir, filename))
291+
}
292+
}
293+
294+
var input string
286295
fmt.Scanln(&input)
287296
}
288297

@@ -294,6 +303,7 @@ func initGameObject() *game {
294303
g.flags.hasGameStarted = false
295304
g.flags.isGameLive = false
296305
g.flags.isGameOver = false
306+
g.flags.inRound = false
297307
g.flags.prePlant = true
298308
g.flags.postPlant = false
299309
g.flags.postWinCon = false
@@ -387,6 +397,7 @@ func processDemo(demoName string) {
387397

388398
//reset various flags
389399
resetRoundFlags := func() {
400+
game.flags.inRound = true
390401
game.flags.prePlant = true
391402
game.flags.postPlant = false
392403
game.flags.postWinCon = false
@@ -396,6 +407,8 @@ func processDemo(demoName string) {
396407
game.flags.ctClutchSteam = 0
397408
game.flags.tMoney = false
398409
game.flags.openingKill = true
410+
game.flags.lastTickProcessed = 0
411+
game.flags.ticksProcessed = 0
399412
}
400413

401414
initTeamPlayer := func(team *common.TeamState, currRoundObj *round) {
@@ -427,14 +440,6 @@ func processDemo(demoName string) {
427440
// Reset round
428441
game.potentialRound = newRound
429442

430-
// if len(game.rounds) < game.flags.roundIntegrityStart {
431-
// //game.potentialRound = currRoundObj
432-
// } else {
433-
// //game.rounds[roundIntegrityStart - 1] = currRoundObj
434-
// fmt.Println(game.rounds[game.flags.roundIntegrityStart - 1].integrityCheck)
435-
// //game.rounds = append(game.rounds, currRoundObj)
436-
// }
437-
438443
//track the number of people alive for clutch checking and record keeping
439444
game.flags.tAlive = len(terrorists.Members())
440445
game.flags.ctAlive = len(counterTerrorists.Members())
@@ -461,6 +466,7 @@ func processDemo(demoName string) {
461466
}
462467

463468
processRoundFinal := func(lastRound bool) {
469+
game.flags.inRound = false
464470
game.potentialRound.endingTick = p.GameState().IngameTick()
465471
game.flags.roundIntegrityEndOfficial = p.GameState().TotalRoundsPlayed()
466472
if lastRound {
@@ -523,6 +529,8 @@ func processDemo(demoName string) {
523529
}
524530

525531
//add multikills & saves & misc
532+
highestImpactPoints := 0.0
533+
mipPlayers := 0
526534
for _, player := range (game.potentialRound).playerStats {
527535
if player.deaths == 0 {
528536
player.kastRounds = 1
@@ -546,19 +554,53 @@ func processDemo(demoName string) {
546554
player._5k = 1
547555
}
548556

557+
if player.impactPoints > highestImpactPoints {
558+
highestImpactPoints = player.impactPoints
559+
}
560+
549561
if player.teamENUM == game.potentialRound.winnerENUM {
550562
player.winPoints = player.impactPoints
563+
551564
player.RF = 1
552-
if player.name == "iNSANEmayne" {
553-
debugMsg := fmt.Sprintf("---------%.2f win points for brod on round %d.------------\n", player.impactPoints, game.potentialRound.roundNum)
554-
debugFile.WriteString(debugMsg)
555-
debugFile.Sync()
556-
}
557565
} else {
558566
player.RA = 1
559567
}
560568
}
561569

570+
for _, player := range (game.potentialRound).playerStats {
571+
if player.impactPoints == highestImpactPoints {
572+
mipPlayers += 1
573+
}
574+
}
575+
for _, player := range (game.potentialRound).playerStats {
576+
if player.impactPoints == highestImpactPoints {
577+
player.mip = 1.0 / float64(mipPlayers)
578+
}
579+
}
580+
581+
//check the lurk
582+
var susLurker uint64
583+
susLurkBlips := 0
584+
invalidLurk := false
585+
for _, player := range game.potentialRound.playerStats {
586+
if player.side == 2 {
587+
if player.lurkerBlips > susLurkBlips {
588+
susLurkBlips = player.lurkerBlips
589+
susLurker = player.steamID
590+
}
591+
}
592+
}
593+
for _, player := range game.potentialRound.playerStats {
594+
if player.side == 2 {
595+
if player.lurkerBlips == susLurkBlips && player.steamID != susLurker {
596+
invalidLurk = true
597+
}
598+
}
599+
}
600+
if !invalidLurk && susLurkBlips > 3 {
601+
game.potentialRound.playerStats[susLurker].lurkRounds = 1
602+
}
603+
562604
//add our valid round
563605
game.rounds = append(game.rounds, game.potentialRound)
564606
}
@@ -569,6 +611,48 @@ func processDemo(demoName string) {
569611

570612
//-------------ALL OUR EVENTS---------------------
571613

614+
p.RegisterEventHandler(func(e events.FrameDone) {
615+
if game.flags.inRound && game.flags.lastTickProcessed+(4*game.tickRate) < p.GameState().IngameTick() {
616+
game.flags.lastTickProcessed = p.GameState().IngameTick()
617+
game.flags.ticksProcessed += 1
618+
619+
//this will be triggered every 4 seconds of in round time after the first 10 seconds
620+
621+
//check for lurker
622+
if game.flags.tAlive > 2 && !game.flags.postWinCon && p.GameState().IngameTick() > (18*game.tickRate)+game.potentialRound.startingTick {
623+
membersT := p.GameState().TeamTerrorists().Members()
624+
for _, terrorist := range membersT {
625+
if terrorist.IsAlive() {
626+
for _, teammate := range membersT {
627+
if terrorist.SteamID64 != teammate.SteamID64 && teammate.IsAlive() {
628+
dist := int(terrorist.Position().Distance(teammate.Position()))
629+
if dist < 500 {
630+
//invalidate the lurk blip b/c we have a close teammate
631+
game.potentialRound.playerStats[terrorist.SteamID64].distanceToTeammates = -999999
632+
}
633+
game.potentialRound.playerStats[terrorist.SteamID64].distanceToTeammates += dist
634+
}
635+
}
636+
}
637+
}
638+
var lurkerSteam uint64
639+
lurkerDist := 999999
640+
for _, terrorist := range membersT {
641+
if terrorist.IsAlive() {
642+
dist := game.potentialRound.playerStats[terrorist.SteamID64].distanceToTeammates
643+
if dist < lurkerDist && dist > 0 {
644+
lurkerDist = dist
645+
lurkerSteam = terrorist.SteamID64
646+
}
647+
}
648+
}
649+
if lurkerSteam != 0 {
650+
game.potentialRound.playerStats[lurkerSteam].lurkerBlips += 1
651+
}
652+
}
653+
}
654+
})
655+
572656
p.RegisterEventHandler(func(e events.RoundStart) {
573657
fmt.Printf("Round Start\n")
574658
})
@@ -908,12 +992,6 @@ func processDemo(demoName string) {
908992
killValue *= ecoMod
909993

910994
pS[e.Killer.SteamID64].killPoints += killValue
911-
if e.Killer.Name == "iNSANEmayne" {
912-
debugMsg := fmt.Sprintf("---------%.2f kill points for brod on round %d.------------\n", killValue, game.potentialRound.roundNum)
913-
debugFile.WriteString(debugMsg)
914-
debugFile.Sync()
915-
}
916-
917995
}
918996

919997
}
@@ -979,8 +1057,8 @@ func processDemo(demoName string) {
9791057
}
9801058
})
9811059

982-
p.RegisterEventHandler(func(e events.PlayerJump) {
983-
//fmt.Printf("Player Jumped\n")
1060+
p.RegisterEventHandler(func(e events.RoundImpactScoreData) {
1061+
fmt.Println("-------ROUNDIMPACTSCOREDATA", e.RawMessage)
9841062
})
9851063

9861064
p.RegisterEventHandler(func(e events.BombPlanted) {

0 commit comments

Comments
 (0)