Skip to content

Commit b749278

Browse files
committed
Fixed unsassigned players becoming CTs
1 parent 6f8a996 commit b749278

File tree

4 files changed

+17
-29
lines changed

4 files changed

+17
-29
lines changed

common/structs.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ type Player struct {
4040
LastAlivePosition r3.Vector
4141
Velocity r3.Vector
4242
EntityID int
43-
TeamID int
4443
Name string
4544
Hp int
4645
Armor int

datatables.go

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,13 @@ func (p *Parser) bindTeamScores() {
8181
team := val.StringVal
8282

8383
var s *TeamState
84-
var t common.Team
8584

8685
switch team {
8786
case "CT":
8887
s = &p.gameState.ctState
89-
t = common.TeamCounterTerrorists
9088

9189
case "TERRORIST":
9290
s = &p.gameState.tState
93-
t = common.TeamTerrorists
9491

9592
case "Unassigned": // Ignore
9693
case "Spectator": // Ignore
@@ -117,16 +114,6 @@ func (p *Parser) bindTeamScores() {
117114
event.Entity.FindProperty("m_scoreTotal").RegisterPropertyUpdateHandler(func(val st.PropValue) {
118115
s.score = val.IntVal
119116
})
120-
121-
// FIXME: This only sets the team at the start. . . We also have a player-specific update handler that changes the team so maybe this is unnecessary?
122-
if teamID != -1 {
123-
s.id = teamID
124-
for _, pl := range p.entityIDToPlayers {
125-
if pl != nil && pl.TeamID == teamID {
126-
pl.Team = t
127-
}
128-
}
129-
}
130117
}
131118
})
132119
})
@@ -211,17 +198,7 @@ func (p *Parser) bindNewPlayer(playerEntity *st.Entity) {
211198
})
212199

213200
playerEntity.FindProperty("m_iTeamNum").RegisterPropertyUpdateHandler(func(val st.PropValue) {
214-
pl.TeamID = val.IntVal
215-
216-
// FIXME: We could probably just cast TeamID to common.Team or not even set it because the teamIDs should be the same. . . needs testing
217-
switch pl.TeamID {
218-
case p.gameState.ctState.id:
219-
pl.Team = common.TeamCounterTerrorists
220-
case p.gameState.tState.id:
221-
pl.Team = common.TeamTerrorists
222-
default:
223-
pl.Team = common.TeamSpectators
224-
}
201+
pl.Team = common.Team(val.IntVal)
225202
})
226203

227204
// Some helpers because I cant be arsed

demoinfocs_test.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ func TestDemoInfoCs(t *testing.T) {
4848
}
4949

5050
fmt.Println("Registering handlers")
51+
gs := p.GameState()
5152
p.RegisterEventHandler(func(e events.RoundEndedEvent) {
52-
gs := p.GameState()
5353
var winner *dem.TeamState
5454
var loser *dem.TeamState
5555
var winnerSide string
@@ -80,6 +80,19 @@ func TestDemoInfoCs(t *testing.T) {
8080
t.Error("Unexprected default value, check output of last round")
8181
}
8282
})
83+
// Check some things at match start
84+
p.RegisterEventHandler(func(events.MatchStartedEvent) {
85+
participants := gs.Participants()
86+
players := gs.PlayingParticipants()
87+
if len(participants) <= len(players) {
88+
// We know the default demo has spectators
89+
t.Error("Expected more participants than players (spectators)")
90+
}
91+
if nPlayers := len(players); nPlayers != 10 {
92+
// We know there should be 10 players at match start in the default demo
93+
t.Error("Expected 10 players; got", nPlayers)
94+
}
95+
})
8396

8497
ts := time.Now()
8598
var done int64

game_state.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,11 @@ func (gs GameState) Participants() []*common.Player {
4747
return r
4848
}
4949

50-
// PlayingParticipants returns all players that aren't spectating.
50+
// PlayingParticipants returns all players that aren't spectating or unassigned.
5151
func (gs GameState) PlayingParticipants() []*common.Player {
5252
r := make([]*common.Player, 0, len(gs.players))
5353
for _, ptcp := range gs.players {
54-
// FIXME: Why do we have to check for nil here???
55-
if ptcp != nil && ptcp.Team != common.TeamSpectators {
54+
if ptcp.Team != common.TeamSpectators && ptcp.Team != common.TeamUnassigned {
5655
r = append(r, ptcp)
5756
}
5857
}

0 commit comments

Comments
 (0)