-
Notifications
You must be signed in to change notification settings - Fork 722
Start game instantly after spawning in Singleplayer #2551
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?
Changes from 20 commits
ef5f38d
d287d6a
454bdf8
5f89241
bf84bd3
8aca6f3
a5920f1
1ae7884
0b12d89
75a4f17
1646095
1c264f8
6a592c4
dc73692
f4aaca2
023eac9
4d3359d
6b9dd7f
a0a7fa7
d6d35b9
2246a13
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 |
|---|---|---|
|
|
@@ -175,6 +175,10 @@ export abstract class DefaultServerConfig implements ServerConfig { | |
| turnIntervalMs(): number { | ||
| return 100; | ||
| } | ||
| // Start game immediately for single player games, with delay for multiplayer games | ||
| startDelay(gameType: GameType): number { | ||
| return gameType === GameType.Singleplayer ? 0 : 2000; | ||
| } | ||
| gameCreationRate(): number { | ||
| return 60 * 1000; | ||
| } | ||
|
|
@@ -273,6 +277,10 @@ export class DefaultConfig implements Config { | |
| return this._serverConfig; | ||
| } | ||
|
|
||
| turnIntervalMs(): number { | ||
| return this._serverConfig.turnIntervalMs(); | ||
| } | ||
|
|
||
| userSettings(): UserSettings { | ||
| if (this._userSettings === null) { | ||
| throw new Error("userSettings is null"); | ||
|
|
@@ -625,9 +633,31 @@ export class DefaultConfig implements Config { | |
| boatMaxNumber(): number { | ||
| return 3; | ||
| } | ||
|
|
||
| numSpawnPhaseTurns(): number { | ||
| return this._gameConfig.gameType === GameType.Singleplayer ? 100 : 300; | ||
| } | ||
| // Amount of ticks for player to change spawn placement in singleplayer | ||
| numGracePeriodTurns(): number { | ||
| return 15; | ||
| } | ||
|
Comment on lines
+640
to
+643
Collaborator
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. I think we should just start immediately on click? If a play picks a bad spawn, then can just start a new game. |
||
| isSpawnPhase( | ||
| ticks: number, | ||
| gameType: GameType, | ||
| firstHumanSpawnTick?: number, | ||
| ): boolean { | ||
| if (ticks > this.numSpawnPhaseTurns()) { | ||
| return false; | ||
| } | ||
| if (gameType !== GameType.Singleplayer) { | ||
| return true; | ||
| } | ||
| if (!firstHumanSpawnTick) { | ||
| return true; | ||
| } | ||
| return ticks <= firstHumanSpawnTick + this.numGracePeriodTurns(); | ||
| } | ||
Lavodan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| numBots(): number { | ||
| return this.bots(); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,6 +69,8 @@ export class GameImpl implements Game { | |
| private _height: number; | ||
| _terraNullius: TerraNulliusImpl; | ||
|
|
||
| private firstHumanSpawnTick: number; | ||
Lavodan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| allianceRequests: AllianceRequestImpl[] = []; | ||
| alliances_: AllianceImpl[] = []; | ||
|
|
||
|
|
@@ -338,7 +340,17 @@ export class GameImpl implements Game { | |
| } | ||
|
|
||
| inSpawnPhase(): boolean { | ||
| return this._ticks <= this.config().numSpawnPhaseTurns(); | ||
| if (!this.firstHumanSpawnTick) { | ||
| const humanSpawned = Array.from(this._players.values()).some( | ||
| (p) => p.type() === PlayerType.Human && p.hasSpawned(), | ||
| ); | ||
| if (humanSpawned) this.firstHumanSpawnTick = this._ticks; | ||
| } | ||
| return this._config.isSpawnPhase( | ||
| this.ticks(), | ||
| this.config().gameConfig().gameType, | ||
| this.firstHumanSpawnTick, | ||
| ); | ||
|
Comment on lines
+343
to
+353
Collaborator
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. how about instead of this we just create a method called: forceEndSpawnPhase() and GameImpl has a field like: private spawnPhaseEnd = flase and then: inSpawnPhase() { then the spawn execution can check if it's a singplayer game and if a human is spawned in it calls this.game.endSpawnPhase() |
||
| } | ||
|
|
||
| ticks(): number { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -475,6 +475,8 @@ export class GameView implements GameMap { | |
|
|
||
| private _map: GameMap; | ||
|
|
||
| private firstHumanSpawnTick: number; | ||
|
|
||
| constructor( | ||
| public worker: WorkerClient, | ||
| private _config: Config, | ||
|
|
@@ -655,7 +657,17 @@ export class GameView implements GameMap { | |
| return this.lastUpdate.tick; | ||
| } | ||
| inSpawnPhase(): boolean { | ||
| return this.ticks() <= this._config.numSpawnPhaseTurns(); | ||
| if (!this.firstHumanSpawnTick) { | ||
| const humanSpawned = this.playerViews().some( | ||
| (p) => p.type() === PlayerType.Human && p.hasSpawned(), | ||
| ); | ||
| if (humanSpawned) this.firstHumanSpawnTick = this.ticks(); | ||
| } | ||
| return this.config().isSpawnPhase( | ||
| this.ticks(), | ||
| this.config().gameConfig().gameType, | ||
| this.firstHumanSpawnTick, | ||
| ); | ||
|
Comment on lines
+660
to
+670
Collaborator
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. Instead let's add a GameStateUpdate interface that has the spawnphase info. we can add more data to in the future |
||
| } | ||
| config(): Config { | ||
| return this._config; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.