@@ -25,10 +25,17 @@ type SchemaPacket = {
2525 ruinsOffset : number
2626}
2727
28+ type ResourcePatternData = {
29+ teamId : number
30+ center : Vector
31+ createRound : number
32+ }
33+
2834export class CurrentMap {
2935 public readonly staticMap : StaticMap
3036 public readonly paint : Int8Array
3137 public readonly markers : [ Int8Array , Int8Array ] // Each team has markers
38+ public readonly resourcePatterns : ResourcePatternData [ ]
3239
3340 get width ( ) : number {
3441 return this . dimension . width
@@ -48,12 +55,16 @@ export class CurrentMap {
4855 this . staticMap = from
4956 this . paint = new Int8Array ( from . initialPaint )
5057 this . markers = [ new Int8Array ( this . width * this . height ) , new Int8Array ( this . width * this . height ) ]
58+ this . resourcePatterns = [ ]
5159 } else {
5260 // Create current map from current map (copy)
5361
5462 this . staticMap = from . staticMap
5563 this . paint = new Int8Array ( from . paint )
5664 this . markers = [ new Int8Array ( from . markers [ 0 ] ) , new Int8Array ( from . markers [ 1 ] ) ]
65+
66+ // Assumes ResourcePatternData is immutable
67+ this . resourcePatterns = [ ...from . resourcePatterns ]
5768 }
5869 }
5970
@@ -78,9 +89,34 @@ export class CurrentMap {
7889 }
7990
8091 /**
81- * Mutates this currentMap to reflect the given turn .
92+ * Mutates this currentMap to reflect the given round .
8293 */
83- applyTurnDelta ( turn : schema . Turn ) : void { }
94+ applyRoundDelta ( round : Round , delta : schema . Round | null ) : void {
95+ // Update resource patterns and remove if they have been broken
96+ const patternMask = 28873275
97+ for ( let i = 0 ; i < this . resourcePatterns . length ; i ++ ) {
98+ const srp = this . resourcePatterns [ i ]
99+ let patternIdx = 0
100+ let patternFailed = false
101+ for ( let y = srp . center . y + 2 ; y >= srp . center . y - 2 ; y -- ) {
102+ for ( let x = srp . center . x - 2 ; x <= srp . center . x + 2 ; x ++ ) {
103+ const idx = this . locationToIndex ( x , y )
104+ const expectedPaint = ( ( patternMask >> patternIdx ) & 1 ) + ( srp . teamId - 1 ) * 2 + 1
105+ const actualPaint = this . paint [ idx ]
106+ if ( actualPaint !== expectedPaint ) {
107+ this . resourcePatterns [ i ] = this . resourcePatterns [ this . resourcePatterns . length - 1 ]
108+ this . resourcePatterns . pop ( )
109+ i --
110+ patternFailed = true
111+ break
112+ }
113+ patternIdx ++
114+ }
115+
116+ if ( patternFailed ) break
117+ }
118+ }
119+ }
84120
85121 draw (
86122 match : Match ,
@@ -152,6 +188,32 @@ export class CurrentMap {
152188 }
153189 }
154190 }
191+
192+ if ( config . showSRPOutlines || config . showSRPText ) {
193+ ctx . globalAlpha = 1
194+ ctx . lineWidth = 0.03
195+ this . resourcePatterns . forEach ( ( srp ) => {
196+ const topLeftCoords = renderUtils . getRenderCoords ( srp . center . x - 2 , srp . center . y + 2 , this . dimension )
197+ const roundsRemaining = Math . max ( srp . createRound + 50 - match . currentRound . roundNumber , - 1 )
198+ if ( roundsRemaining >= 0 && config . showSRPText ) {
199+ const label = roundsRemaining . toString ( )
200+ ctx . fillStyle = 'white'
201+ ctx . textAlign = 'right'
202+ ctx . font = '1px monospace'
203+ ctx . shadowColor = 'black'
204+ ctx . shadowBlur = 4
205+ ctx . scale ( 0.4 , 0.4 )
206+ ctx . fillText ( label , ( topLeftCoords . x + 3 ) * 2.5 , ( topLeftCoords . y + 2.5 ) * 2.5 )
207+ ctx . scale ( 2.5 , 2.5 )
208+ ctx . shadowColor = ''
209+ ctx . shadowBlur = 0
210+ ctx . textAlign = 'start'
211+ } else if ( roundsRemaining === - 1 && config . showSRPOutlines ) {
212+ ctx . strokeStyle = teamColors [ srp . teamId - 1 ]
213+ ctx . strokeRect ( topLeftCoords . x , topLeftCoords . y , 5 , 5 )
214+ }
215+ } )
216+ }
155217 }
156218
157219 getTooltipInfo ( square : Vector , match : Match ) : string [ ] {
@@ -163,6 +225,7 @@ export class CurrentMap {
163225 const paint = this . paint [ schemaIdx ]
164226 const wall = this . staticMap . walls [ schemaIdx ]
165227 const ruin = this . staticMap . ruins . find ( ( r ) => r . x === square . x && r . y === square . y )
228+ const srp = this . resourcePatterns . find ( ( r ) => r . center . x === square . x && r . center . y === square . y )
166229 const markerA = this . markers [ 0 ] [ schemaIdx ]
167230 const markerB = this . markers [ 1 ] [ schemaIdx ]
168231
@@ -186,6 +249,14 @@ export class CurrentMap {
186249 if ( ruin ) {
187250 info . push ( 'Ruin' )
188251 }
252+ if ( srp ) {
253+ const roundsRemaining = Math . max ( srp . createRound + 50 - match . currentRound . roundNumber , 0 )
254+ if ( roundsRemaining === 0 ) {
255+ info . push ( `${ TEAM_COLOR_NAMES [ srp . teamId - 1 ] } SRP Center (Active)` )
256+ } else {
257+ info . push ( `${ TEAM_COLOR_NAMES [ srp . teamId - 1 ] } SRP Center (${ roundsRemaining } Rounds Left)` )
258+ }
259+ }
189260
190261 return info
191262 }
0 commit comments