Skip to content

Commit d254861

Browse files
committed
Move some constants to events package (#16)
1 parent fc02e7f commit d254861

File tree

4 files changed

+64
-64
lines changed

4 files changed

+64
-64
lines changed

common/common.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
// Package common contains common types, constants and functions used over different demoinfocs packages.
2-
// Some constants prefixes:
3-
// MVPReason - the reason why someone got the MVP award.
4-
// HG - HitGroup - where a bullet hit the player.
5-
// EE - EquipmentElement - basically the weapon identifiers.
6-
// RER - RoundEndReason - why the round ended (bomb exploded, defused, time ran out. . .).
7-
// EC - EquipmentClass - type of equipment (pistol, smg, heavy. . .).
82
package common
93

104
import (

common/constants.go

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,6 @@ package common
33
const weaponPrefix = "weapon_"
44

55
type (
6-
// RoundMVPReason is the type for the various MVPReasonYXZ constants.
7-
RoundMVPReason byte
8-
9-
// HitGroup is the type for the various HitGroupXYZ constants.
10-
HitGroup byte
11-
12-
// RoundEndReason is the type for the various RoundEndReasonXYZ constants.
13-
RoundEndReason byte
14-
156
// Team is the type for the various TeamXYZ constants.
167
Team byte
178

@@ -22,49 +13,6 @@ type (
2213
EquipmentClass int
2314
)
2415

25-
// RoundMVPReasons constants give information about why a player got the MVP award.
26-
const (
27-
MVPReasonMostEliminations RoundMVPReason = 1
28-
MVPReasonBombDefused RoundMVPReason = 2
29-
MVPReasonBombPlanted RoundMVPReason = 3
30-
)
31-
32-
// HitGroup constants give information about where a player got hit.
33-
// e.g. head, chest, legs etc.
34-
const (
35-
HitGroupGeneric HitGroup = 0
36-
HitGroupHead HitGroup = 1
37-
HitGroupChest HitGroup = 2
38-
HitGroupStomach HitGroup = 3
39-
HitGroupLeftArm HitGroup = 4
40-
HitGroupRightArm HitGroup = 5
41-
HitGroupLeftLeg HitGroup = 6
42-
HitGroupRightLeg HitGroup = 7
43-
HitGroupGear HitGroup = 10
44-
)
45-
46-
// RoundEndReasons constants give information about why a round ended (Bomb defused, exploded etc.).
47-
const (
48-
RoundEndReasonTargetBombed RoundEndReason = 1
49-
RoundEndReasonVIPEscaped RoundEndReason = 2
50-
RoundEndReasonVIPKilled RoundEndReason = 3
51-
RoundEndReasonTerroristsEscaped RoundEndReason = 4
52-
RoundEndReasonCTStoppedEscape RoundEndReason = 5
53-
RoundEndReasonTerroristsStopped RoundEndReason = 6
54-
RoundEndReasonBombDefused RoundEndReason = 7
55-
RoundEndReasonCTWin RoundEndReason = 8
56-
RoundEndReasonTerroristsWin RoundEndReason = 9
57-
RoundEndReasonDraw RoundEndReason = 10
58-
RoundEndReasonHostagesRescued RoundEndReason = 11
59-
RoundEndReasonTargetSaved RoundEndReason = 12
60-
RoundEndReasonHostagesNotRescued RoundEndReason = 13
61-
RoundEndReasonTerroristsNotEscaped RoundEndReason = 14
62-
RoundEndReasonVIPNotEscaped RoundEndReason = 15
63-
RoundEndReasonGameStart RoundEndReason = 16
64-
RoundEndReasonTerroristsSurrender RoundEndReason = 17
65-
RoundEndReasonCTSurrender RoundEndReason = 18
66-
)
67-
6816
// Team constants give information about which team a player is on.
6917
const (
7018
TeamUnassigned Team = iota

events/events.go

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,61 @@ type MatchStartedEvent struct{}
1717
// RoundAnnounceMatchStartedEvent signals that the announcement "Match Started" has been displayed.
1818
type RoundAnnounceMatchStartedEvent struct{}
1919

20+
// RoundEndReason is the type for the various RoundEndReasonXYZ constants.
21+
//
22+
// See RoundEndedEvent.
23+
type RoundEndReason byte
24+
25+
// RoundEndReason constants give information about why a round ended (Bomb defused, exploded etc.).
26+
const (
27+
RoundEndReasonTargetBombed RoundEndReason = 1
28+
RoundEndReasonVIPEscaped RoundEndReason = 2
29+
RoundEndReasonVIPKilled RoundEndReason = 3
30+
RoundEndReasonTerroristsEscaped RoundEndReason = 4
31+
RoundEndReasonCTStoppedEscape RoundEndReason = 5
32+
RoundEndReasonTerroristsStopped RoundEndReason = 6
33+
RoundEndReasonBombDefused RoundEndReason = 7
34+
RoundEndReasonCTWin RoundEndReason = 8
35+
RoundEndReasonTerroristsWin RoundEndReason = 9
36+
RoundEndReasonDraw RoundEndReason = 10
37+
RoundEndReasonHostagesRescued RoundEndReason = 11
38+
RoundEndReasonTargetSaved RoundEndReason = 12
39+
RoundEndReasonHostagesNotRescued RoundEndReason = 13
40+
RoundEndReasonTerroristsNotEscaped RoundEndReason = 14
41+
RoundEndReasonVIPNotEscaped RoundEndReason = 15
42+
RoundEndReasonGameStart RoundEndReason = 16
43+
RoundEndReasonTerroristsSurrender RoundEndReason = 17
44+
RoundEndReasonCTSurrender RoundEndReason = 18
45+
)
46+
2047
// RoundEndedEvent signals that a round just finished.
2148
// Attention: TeamState.Score() won't be up to date yet after this.
2249
// Add +1 to the winner's score as a workaround.
2350
type RoundEndedEvent struct {
2451
Message string
25-
Reason common.RoundEndReason
52+
Reason RoundEndReason
2653
Winner common.Team
2754
}
2855

2956
// RoundOfficiallyEndedEvent signals that the round 'has officially ended', not exactly sure what that is tbh.
3057
type RoundOfficiallyEndedEvent struct{}
3158

59+
// RoundMVPReason is the type for the various MVPReasonYXZ constants.
60+
//
61+
// See RoundMVPEvent.
62+
type RoundMVPReason byte
63+
64+
// RoundMVPReasons constants give information about why a player got the MVP award.
65+
const (
66+
MVPReasonMostEliminations RoundMVPReason = 1
67+
MVPReasonBombDefused RoundMVPReason = 2
68+
MVPReasonBombPlanted RoundMVPReason = 3
69+
)
70+
3271
// RoundMVPEvent signals the announcement of the last rounds MVP.
3372
type RoundMVPEvent struct {
3473
Player *common.Player
35-
Reason common.RoundMVPReason
74+
Reason RoundMVPReason
3675
}
3776

3877
// RoundStartedEvent signals that a new round has started.
@@ -226,6 +265,25 @@ type BombBeginDefuseEvent struct {
226265

227266
func (BombBeginDefuseEvent) implementsBombEventIf() {}
228267

268+
// HitGroup is the type for the various HitGroupXYZ constants.
269+
//
270+
// See PlayerHurtEvent.
271+
type HitGroup byte
272+
273+
// HitGroup constants give information about where a player got hit.
274+
// e.g. head, chest, legs etc.
275+
const (
276+
HitGroupGeneric HitGroup = 0
277+
HitGroupHead HitGroup = 1
278+
HitGroupChest HitGroup = 2
279+
HitGroupStomach HitGroup = 3
280+
HitGroupLeftArm HitGroup = 4
281+
HitGroupRightArm HitGroup = 5
282+
HitGroupLeftLeg HitGroup = 6
283+
HitGroupRightLeg HitGroup = 7
284+
HitGroupGear HitGroup = 10
285+
)
286+
229287
// PlayerHurtEvent signals that a player has been damaged.
230288
type PlayerHurtEvent struct {
231289
Player *common.Player
@@ -236,7 +294,7 @@ type PlayerHurtEvent struct {
236294
WeaponString string // Wrong for CZ, M4A1-S etc.
237295
HealthDamage int
238296
ArmorDamage int
239-
HitGroup common.HitGroup
297+
HitGroup HitGroup
240298
}
241299

242300
// PlayerBindEvent signals that a player has connected.

game_events.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func (p *Parser) handleGameEvent(ge *msg.CSVCMsg_GameEvent) {
7575

7676
p.eventDispatcher.Dispatch(events.RoundEndedEvent{
7777
Message: data["message"].GetValString(),
78-
Reason: common.RoundEndReason(data["reason"].GetValByte()),
78+
Reason: events.RoundEndReason(data["reason"].GetValByte()),
7979
Winner: t,
8080
})
8181

@@ -87,7 +87,7 @@ func (p *Parser) handleGameEvent(ge *msg.CSVCMsg_GameEvent) {
8787

8888
p.eventDispatcher.Dispatch(events.RoundMVPEvent{
8989
Player: p.gameState.players[int(data["userid"].GetValShort())],
90-
Reason: common.RoundMVPReason(data["reason"].GetValShort()),
90+
Reason: events.RoundMVPReason(data["reason"].GetValShort()),
9191
})
9292

9393
case "bot_takeover": // Bot got taken over
@@ -151,7 +151,7 @@ func (p *Parser) handleGameEvent(ge *msg.CSVCMsg_GameEvent) {
151151
Armor: int(data["armor"].GetValByte()),
152152
HealthDamage: int(data["dmg_health"].GetValShort()),
153153
ArmorDamage: int(data["dmg_armor"].GetValByte()),
154-
HitGroup: common.HitGroup(data["hitgroup"].GetValByte()),
154+
HitGroup: events.HitGroup(data["hitgroup"].GetValByte()),
155155
Weapon: getAttackingWeapon(&wep, attacker),
156156
})
157157

0 commit comments

Comments
 (0)