-
Notifications
You must be signed in to change notification settings - Fork 1k
spawn #3810
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
spawn #3810
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import { Execution, Game } from "../game/Game"; | ||
|
|
||
| export class SpawnTimerExecution implements Execution { | ||
| private mg: Game; | ||
|
|
||
| init(mg: Game, ticks: number): void { | ||
| this.mg = mg; | ||
| } | ||
|
|
||
| tick(ticks: number): void { | ||
| if (this.mg.ticks() > this.mg.config().numSpawnPhaseTurns()) { | ||
| this.mg.endSpawnPhase(); | ||
| } | ||
| } | ||
|
|
||
| isActive(): boolean { | ||
| return this.mg.inSpawnPhase(); | ||
| } | ||
|
|
||
| activeDuringSpawnPhase(): boolean { | ||
| return true; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -18,6 +18,7 @@ import { | |||||||||||||||||||||||
| Execution, | ||||||||||||||||||||||||
| Game, | ||||||||||||||||||||||||
| GameMode, | ||||||||||||||||||||||||
| GameType, | ||||||||||||||||||||||||
| GameUpdates, | ||||||||||||||||||||||||
| HumansVsNations, | ||||||||||||||||||||||||
| MessageType, | ||||||||||||||||||||||||
|
|
@@ -76,6 +77,7 @@ export type CellString = string; | |||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| export class GameImpl implements Game { | ||||||||||||||||||||||||
| private _ticks = 0; | ||||||||||||||||||||||||
| private startTick: number | null = null; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| private unInitExecs: Execution[] = []; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
@@ -409,7 +411,15 @@ export class GameImpl implements Game { | |||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| inSpawnPhase(): boolean { | ||||||||||||||||||||||||
| return this._ticks <= this.config().numSpawnPhaseTurns(); | ||||||||||||||||||||||||
| return this.startTick === null; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| endSpawnPhase(): void { | ||||||||||||||||||||||||
| this.startTick = this._ticks; | ||||||||||||||||||||||||
| this.addUpdate({ | ||||||||||||||||||||||||
| type: GameUpdateType.SpawnPhaseEnd, | ||||||||||||||||||||||||
| startTick: this.startTick, | ||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| ticks(): number { | ||||||||||||||||||||||||
|
|
@@ -458,6 +468,17 @@ export class GameImpl implements Game { | |||||||||||||||||||||||
| for (const tile of waterChangedTiles) { | ||||||||||||||||||||||||
| this.recordTileUpdate(tile); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| if ( | ||||||||||||||||||||||||
| this.config().gameConfig().gameType !== GameType.Singleplayer && | ||||||||||||||||||||||||
| this._ticks === this.startTick | ||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||
| this.addUpdate({ | ||||||||||||||||||||||||
| type: GameUpdateType.SpawnPhaseEnd, | ||||||||||||||||||||||||
| startTick: this.startTick, | ||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
Comment on lines
+472
to
+480
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid emitting On the tick where Suggested change- if (
- this.config().gameConfig().gameType !== GameType.Singleplayer &&
- this._ticks === this.startTick
- ) {
- this.addUpdate({
- type: GameUpdateType.SpawnPhaseEnd,
- startTick: this.startTick,
- });
- }
-
this._ticks++;
return this.updates;📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| this._ticks++; | ||||||||||||||||||||||||
| return this.updates; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
@@ -819,20 +840,30 @@ export class GameImpl implements Game { | |||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| public isSpawnImmunityActive(): boolean { | ||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||
| this.config().numSpawnPhaseTurns() + | ||||||||||||||||||||||||
| this.config().spawnImmunityDuration() > | ||||||||||||||||||||||||
| this.ticks() | ||||||||||||||||||||||||
| this.inSpawnPhase() || | ||||||||||||||||||||||||
| this.ticksSinceStart() < this.config().spawnImmunityDuration() | ||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| public elapsedGameSeconds(): number { | ||||||||||||||||||||||||
| return this.ticksSinceStart() / 10; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| public isNationSpawnImmunityActive(): boolean { | ||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||
| this.config().numSpawnPhaseTurns() + | ||||||||||||||||||||||||
| this.config().nationSpawnImmunityDuration() > | ||||||||||||||||||||||||
| this.ticks() | ||||||||||||||||||||||||
| this.inSpawnPhase() || | ||||||||||||||||||||||||
| this.ticksSinceStart() < this.config().nationSpawnImmunityDuration() | ||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| private ticksSinceStart(): number { | ||||||||||||||||||||||||
| if (this.inSpawnPhase()) { | ||||||||||||||||||||||||
| return 0; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| return Math.max(0, this.ticks() - this.startTick!); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
Comment on lines
+848
to
+865
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keep time as integers inside
As per coding guidelines 🤖 Prompt for AI Agents |
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| sendEmojiUpdate(msg: EmojiMessage): void { | ||||||||||||||||||||||||
| this.addUpdate({ | ||||||||||||||||||||||||
| type: GameUpdateType.Emoji, | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
End spawn phase on the configured tick, not one tick later.
executeNextTick()runs executions before_ticksis incremented, so>delays the transition tonumSpawnPhaseTurns() + 1. That shifts the countdown,startTick, and spawn-immunity window by one tick.Suggested change
tick(ticks: number): void { - if (this.mg.ticks() > this.mg.config().numSpawnPhaseTurns()) { + if (this.mg.ticks() >= this.mg.config().numSpawnPhaseTurns()) { this.mg.endSpawnPhase(); } }📝 Committable suggestion
🤖 Prompt for AI Agents