Skip to content

Commit 097b925

Browse files
committed
fix SmokeStart wrong UniqueID2() - #596
1 parent 5155380 commit 097b925

File tree

3 files changed

+17
-25
lines changed

3 files changed

+17
-25
lines changed

pkg/demoinfocs/game_events.go

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ func (geh gameEventHandler) clearGrenadeProjectiles() {
263263
}
264264

265265
// Thrown grenades could not be deleted at the end of the round (if they are thrown at the very end, they never get destroyed)
266-
geh.gameState().thrownGrenades = make(map[*common.Player][]*common.Equipment)
266+
geh.gameState().thrownGrenades = make(map[*common.Player]map[common.EquipmentType]*common.Equipment)
267267
geh.gameState().flyingFlashbangs = make([]*FlyingFlashbang, 0)
268268
}
269269

@@ -933,7 +933,12 @@ func (geh gameEventHandler) addThrownGrenade(p *common.Player, wep *common.Equip
933933
}
934934

935935
gameState := geh.gameState()
936-
gameState.thrownGrenades[p] = append(gameState.thrownGrenades[p], wep)
936+
937+
if gameState.thrownGrenades[p] == nil {
938+
gameState.thrownGrenades[p] = make(map[common.EquipmentType]*common.Equipment)
939+
}
940+
941+
gameState.thrownGrenades[p][wep.Type] = wep
937942
}
938943

939944
func (geh gameEventHandler) getThrownGrenade(p *common.Player, wepType common.EquipmentType) *common.Equipment {
@@ -942,14 +947,11 @@ func (geh gameEventHandler) getThrownGrenade(p *common.Player, wepType common.Eq
942947
return nil
943948
}
944949

945-
// Get the first weapon we found for this player with this weapon type
946-
for _, thrownGrenade := range geh.gameState().thrownGrenades[p] {
947-
if isSameEquipmentElement(thrownGrenade.Type, wepType) {
948-
return thrownGrenade
949-
}
950+
if geh.gameState().thrownGrenades[p] == nil {
951+
return nil
950952
}
951953

952-
return nil
954+
return geh.gameState().thrownGrenades[p][wepType]
953955
}
954956

955957
func (geh gameEventHandler) deleteThrownGrenade(p *common.Player, wepType common.EquipmentType) {
@@ -958,17 +960,7 @@ func (geh gameEventHandler) deleteThrownGrenade(p *common.Player, wepType common
958960
return
959961
}
960962

961-
gameState := geh.gameState()
962-
963-
// Delete the first weapon we found with this weapon type
964-
for i, weapon := range gameState.thrownGrenades[p] {
965-
// If same weapon type
966-
// OR if it's an EqIncendiary we must check for EqMolotov too because of geh.infernoExpire() handling ?
967-
if isSameEquipmentElement(wepType, weapon.Type) {
968-
gameState.thrownGrenades[p] = append(gameState.thrownGrenades[p][:i], gameState.thrownGrenades[p][i+1:]...)
969-
return
970-
}
971-
}
963+
delete(geh.gameState().thrownGrenades[p], wepType)
972964
}
973965

974966
func (geh gameEventHandler) attackerWeaponType(wepType common.EquipmentType, victimUserID int32) common.EquipmentType {

pkg/demoinfocs/game_events_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func TestAddThrownGrenade(t *testing.T) {
113113

114114
assert.NotEmpty(t, p.gameState.thrownGrenades)
115115
assert.NotEmpty(t, p.gameState.thrownGrenades[pl])
116-
assert.Equal(t, p.gameState.thrownGrenades[pl][0], he)
116+
assert.Equal(t, p.gameState.thrownGrenades[pl][common.EqHE], he)
117117
}
118118

119119
func TestGetThrownGrenade_NilPlayer(t *testing.T) {

pkg/demoinfocs/game_state.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ type gameState struct {
3636
isFreezetime bool
3737
isMatchStarted bool
3838
overtimeCount int
39-
lastFlash lastFlash // Information about the last flash that exploded, used to find the attacker and projectile for player_blind events
40-
currentDefuser *common.Player // Player currently defusing the bomb, if any
41-
currentPlanter *common.Player // Player currently planting the bomb, if any
42-
thrownGrenades map[*common.Player][]*common.Equipment // Information about every player's thrown grenades (from the moment they are thrown to the moment their effect is ended)
39+
lastFlash lastFlash // Information about the last flash that exploded, used to find the attacker and projectile for player_blind events
40+
currentDefuser *common.Player // Player currently defusing the bomb, if any
41+
currentPlanter *common.Player // Player currently planting the bomb, if any
42+
thrownGrenades map[*common.Player]map[common.EquipmentType]*common.Equipment // Information about every player's thrown grenades (from the moment they are thrown to the moment their effect is ended)
4343
rules gameRules
4444
demoInfo demoInfoProvider
4545
lastRoundStartEvent *events.RoundStart // Used to dispatch this event after a possible MatchStartedChanged event
@@ -233,7 +233,7 @@ func newGameState(demoInfo demoInfoProvider) *gameState {
233233
weapons: make(map[int]*common.Equipment),
234234
hostages: make(map[int]*common.Hostage),
235235
entities: make(map[int]st.Entity),
236-
thrownGrenades: make(map[*common.Player][]*common.Equipment),
236+
thrownGrenades: make(map[*common.Player]map[common.EquipmentType]*common.Equipment),
237237
flyingFlashbangs: make([]*FlyingFlashbang, 0),
238238
lastFlash: lastFlash{
239239
projectileByPlayer: make(map[*common.Player]*common.GrenadeProjectile),

0 commit comments

Comments
 (0)