mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-18 19:12:45 +00:00
implement cities
This commit is contained in:
|
Before Width: | Height: | Size: 129 B After Width: | Height: | Size: 129 B |
@@ -8,6 +8,7 @@ import { EventBus } from "../../../core/EventBus";
|
||||
import anchorIcon from '../../../../resources/images/AnchorIcon.png';
|
||||
import missileSiloIcon from '../../../../resources/images/MissileSiloUnit.png';
|
||||
import shieldIcon from '../../../../resources/images/ShieldIcon.png';
|
||||
import cityIcon from '../../../../resources/images/CityIcon.png';
|
||||
|
||||
interface UnitRenderConfig {
|
||||
icon: string;
|
||||
@@ -38,6 +39,11 @@ export class StructureLayer implements Layer {
|
||||
icon: shieldIcon,
|
||||
borderRadius: 8,
|
||||
territoryRadius: 6
|
||||
},
|
||||
[UnitType.City]: {
|
||||
icon: cityIcon,
|
||||
borderRadius: 8,
|
||||
territoryRadius: 6
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import missileSiloIcon from '../../../../../resources/images/MissileSiloIconWhit
|
||||
import goldCoinIcon from '../../../../../resources/images/GoldCoinIcon.svg';
|
||||
import portIcon from '../../../../../resources/images/PortIcon.svg';
|
||||
import shieldIcon from '../../../../../resources/images/ShieldIconWhite.svg';
|
||||
import cityIcon from '../../../../../resources/images/CityIconWhite.svg';
|
||||
import { renderNumber } from '../../Utils';
|
||||
import { ContextMenuEvent } from '../../../InputHandler';
|
||||
|
||||
@@ -27,7 +28,8 @@ const buildTable: BuildItemDisplay[][] = [
|
||||
{ unitType: UnitType.Battleship, icon: battleshipIcon },
|
||||
{ unitType: UnitType.Port, icon: portIcon },
|
||||
{ unitType: UnitType.MissileSilo, icon: missileSiloIcon },
|
||||
{ unitType: UnitType.DefensePost, icon: shieldIcon }
|
||||
{ unitType: UnitType.DefensePost, icon: shieldIcon },
|
||||
{ unitType: UnitType.City, icon: cityIcon }
|
||||
]
|
||||
];
|
||||
|
||||
|
||||
@@ -46,6 +46,7 @@ export interface Config {
|
||||
}
|
||||
attackAmount(attacker: Player, defender: Player | TerraNullius): number
|
||||
maxPopulation(player: Player): number
|
||||
cityPopulationIncrease(): number
|
||||
boatAttackAmount(attacker: Player, defender: Player | TerraNullius): number
|
||||
boatMaxDistance(): number
|
||||
boatMaxNumber(): number
|
||||
|
||||
@@ -8,6 +8,10 @@ import { pastelTheme } from "./PastelTheme";
|
||||
|
||||
export class DefaultConfig implements Config {
|
||||
|
||||
cityPopulationIncrease(): number {
|
||||
return 250_000
|
||||
}
|
||||
|
||||
falloutDefenseModifier(): number {
|
||||
return 2
|
||||
}
|
||||
@@ -80,6 +84,11 @@ export class DefaultConfig implements Config {
|
||||
cost: (p: Player) => Math.pow(2, p.units(UnitType.Port).length) * 100_000,
|
||||
territoryBound: true
|
||||
}
|
||||
case UnitType.City:
|
||||
return {
|
||||
cost: (p: Player) => Math.pow(2, p.units(UnitType.Port).length) * 250_000,
|
||||
territoryBound: true
|
||||
}
|
||||
default:
|
||||
assertNever(type)
|
||||
}
|
||||
@@ -217,7 +226,7 @@ export class DefaultConfig implements Config {
|
||||
if (player.type() == PlayerType.Bot) {
|
||||
return maxPop
|
||||
}
|
||||
return maxPop * 2
|
||||
return maxPop * 2 + player.units(UnitType.City).length * this.cityPopulationIncrease()
|
||||
}
|
||||
|
||||
populationIncreaseRate(player: Player): number {
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
import { Cell, DefenseBonus, Execution, MutableGame, MutablePlayer, MutableUnit, PlayerID, Tile, UnitType } from "../game/Game";
|
||||
import { bfs, dist } from "../Util";
|
||||
|
||||
export class CityExecution implements Execution {
|
||||
|
||||
private player: MutablePlayer
|
||||
private mg: MutableGame
|
||||
private city: MutableUnit
|
||||
private tile: Tile
|
||||
private active: boolean = true
|
||||
|
||||
constructor(private ownerId: PlayerID, private cell: Cell) { }
|
||||
|
||||
init(mg: MutableGame, ticks: number): void {
|
||||
this.mg = mg
|
||||
this.tile = mg.tile(this.cell)
|
||||
this.player = mg.player(this.ownerId)
|
||||
}
|
||||
|
||||
tick(ticks: number): void {
|
||||
if (this.city == null) {
|
||||
const spawnTile = this.player.canBuild(UnitType.City, this.tile)
|
||||
if (spawnTile == false) {
|
||||
console.warn('cannot build Defense Post')
|
||||
this.active = false
|
||||
return
|
||||
}
|
||||
this.city = this.player.buildUnit(UnitType.City, 0, spawnTile)
|
||||
}
|
||||
if (!this.city.isActive()) {
|
||||
this.active = false
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
owner(): MutablePlayer {
|
||||
return null
|
||||
}
|
||||
|
||||
isActive(): boolean {
|
||||
return this.active
|
||||
}
|
||||
|
||||
activeDuringSpawnPhase(): boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
}
|
||||
@@ -23,6 +23,7 @@ import { BattleshipExecution } from "./BattleshipExecution";
|
||||
import { PathFinder } from "../pathfinding/PathFinding";
|
||||
import { WorkerClient } from "../worker/WorkerClient";
|
||||
import { DefensePostExecution } from "./DefensePostExecution";
|
||||
import { CityExecution } from "./CityExecution";
|
||||
|
||||
|
||||
|
||||
@@ -100,6 +101,8 @@ export class Executor {
|
||||
return new MissileSiloExecution(intent.player, new Cell(intent.x, intent.y))
|
||||
case UnitType.DefensePost:
|
||||
return new DefensePostExecution(intent.player, new Cell(intent.x, intent.y))
|
||||
case UnitType.City:
|
||||
return new CityExecution(intent.player, new Cell(intent.x, intent.y))
|
||||
default:
|
||||
throw Error(`unit type ${intent.unit} not supported`)
|
||||
}
|
||||
|
||||
@@ -39,7 +39,8 @@ export enum UnitType {
|
||||
HydrogenBomb = "Hydrogen Bomb",
|
||||
TradeShip = "Trade Ship",
|
||||
MissileSilo = "Missile Silo",
|
||||
DefensePost = "Defense Post"
|
||||
DefensePost = "Defense Post",
|
||||
City = "City"
|
||||
}
|
||||
|
||||
export class Nation {
|
||||
|
||||
@@ -372,6 +372,8 @@ export class PlayerImpl implements MutablePlayer {
|
||||
return this.transportShipSpawn(targetTile)
|
||||
case UnitType.TradeShip:
|
||||
return this.tradeShipSpawn(targetTile)
|
||||
case UnitType.City:
|
||||
return this.landBasedStructureSpawn(targetTile)
|
||||
default:
|
||||
assertNever(unitType)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user