11package common
22
33import (
4+ "fmt"
45 "math/rand"
56 "sort"
67
@@ -16,9 +17,7 @@ import (
1617//
1718// See also: Inferno.Active() and Fire.IsBurning
1819type Inferno struct {
19- Entity st.IEntity
20- EntityID int // Same as Entity.ID(), use Entity.ID() instead
21- Fires []* Fire
20+ Entity st.IEntity
2221
2322 // uniqueID is used to distinguish different infernos (which potentially have the same, reused entityID) from each other.
2423 uniqueID int64
@@ -32,36 +31,65 @@ type Fire struct {
3231 IsBurning bool
3332}
3433
34+ // Fires is a collection of fires that provides utility functions for things like calculation of 2D & 3D convex hulls.
35+ type Fires struct {
36+ s []Fire
37+ }
38+
3539// UniqueID returns the unique id of the inferno.
3640// The unique id is a random int generated internally by this library and can be used to differentiate
3741// infernos from each other. This is needed because demo-files reuse entity ids.
3842func (inf Inferno ) UniqueID () int64 {
3943 return inf .uniqueID
4044}
4145
42- // Active returns an Inferno containing only the active fires of the original.
43- // The returned Inferno will have the same Unique-ID as the original.
44- func (inf Inferno ) Active () Inferno {
45- res := Inferno {
46- uniqueID : inf .uniqueID ,
46+ // Fires returns all fires (past + present).
47+ // Some are currently active and some have extinguished (see Fire.IsBurning).
48+ func (inf Inferno ) Fires () Fires {
49+ entity := inf .Entity
50+ origin := entity .Position ()
51+
52+ var fires []Fire
53+ nFires := entity .PropertyValueMust ("m_fireCount" ).IntVal
54+
55+ for i := 0 ; i < nFires ; i ++ {
56+ iStr := fmt .Sprintf ("%03d" , i )
57+ offset := r3.Vector {
58+ X : float64 (entity .PropertyValueMust ("m_fireXDelta." + iStr ).IntVal ),
59+ Y : float64 (entity .PropertyValueMust ("m_fireYDelta." + iStr ).IntVal ),
60+ Z : float64 (entity .PropertyValueMust ("m_fireZDelta." + iStr ).IntVal ),
61+ }
62+
63+ fire := Fire {
64+ Vector : origin .Add (offset ),
65+ IsBurning : entity .PropertyValueMust ("m_bFireIsBurning." + iStr ).IntVal == 1 ,
66+ }
67+
68+ fires = append (fires , fire )
4769 }
4870
49- res .Fires = make ([]* Fire , 0 , len (inf .Fires ))
71+ return Fires {s : fires }
72+ }
73+
74+ // Active returns all currently active fires (only Fire.IsBurning == true).
75+ func (f Fires ) Active () Fires {
76+ allFires := f .s
77+ active := make ([]Fire , 0 , len (allFires ))
5078
51- for _ , f := range inf . Fires {
79+ for _ , f := range allFires {
5280 if f .IsBurning {
53- res . Fires = append (res . Fires , f )
81+ active = append (active , f )
5482 }
5583 }
5684
57- return res
85+ return Fires { s : active }
5886}
5987
6088// ConvexHull2D returns clockwise sorted corner points making up the 2D convex hull of all the fires in the inferno.
6189// Useful for drawing on 2D maps.
62- func (inf Inferno ) ConvexHull2D () []r2.Point {
63- pointCloud := make ([]r3.Vector , len (inf . Fires ))
64- for i , f := range inf . Fires {
90+ func (f Fires ) ConvexHull2D () []r2.Point {
91+ pointCloud := make ([]r3.Vector , len (f . s ))
92+ for i , f := range f . s {
6593 pointCloud [i ] = f .Vector
6694 pointCloud [i ].Z = 0
6795 }
@@ -135,25 +163,16 @@ func sortPointsClockwise(points []r2.Point) {
135163}
136164
137165// ConvexHull3D returns the 3D convex hull of all the fires in the inferno.
138- func (inf Inferno ) ConvexHull3D () quickhull.ConvexHull {
139- pointCloud := make ([]r3.Vector , len (inf . Fires ))
166+ func (f Fires ) ConvexHull3D () quickhull.ConvexHull {
167+ pointCloud := make ([]r3.Vector , len (f . s ))
140168
141- for i , f := range inf . Fires {
169+ for i , f := range f . s {
142170 pointCloud [i ] = f .Vector
143171 }
144172
145173 return convexHull (pointCloud )
146174}
147175
148- // Owner returns the player who threw the fire grenade.
149- // Could be nil if the player disconnected after throwing it.
150- //
151- // Deprecated: Owner() exists for historical compatibility
152- // and should not be used. Use Thrower() instead.
153- func (inf Inferno ) Owner () * Player {
154- return inf .Thrower ()
155- }
156-
157176// Thrower returns the player who threw the fire grenade.
158177// Could be nil if the player disconnected after throwing it.
159178func (inf Inferno ) Thrower () * Player {
@@ -170,7 +189,6 @@ func convexHull(pointCloud []r3.Vector) quickhull.ConvexHull {
170189func NewInferno (demoInfoProvider demoInfoProvider , entity st.IEntity ) * Inferno {
171190 return & Inferno {
172191 Entity : entity ,
173- EntityID : entity .ID (),
174192 uniqueID : rand .Int63 (),
175193 demoInfoProvider : demoInfoProvider ,
176194 }
0 commit comments