add defense post unit (no execution)

This commit is contained in:
Evan
2024-11-30 20:54:42 -08:00
parent 7ff0509b40
commit e7039d3e07
13 changed files with 126 additions and 8 deletions
+2 -1
View File
@@ -200,8 +200,9 @@
* make mini map for path finding DONE 11/29/2024
* have NPCs build destroyers and battleships DONE 11/30/2024
* add info view on top right DONE 11/30/2024
* add info view for units
* add info view for units DONE 11/30/2024
* add defense post
* record single player games
* add radiation from nuke
* add cities
* create alternate view to show friendly & enemy units
Binary file not shown.

After

Width:  |  Height:  |  Size: 112 B

+57
View File
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
width="24"
height="24"
viewBox="0 0 24 24"
version="1.1"
id="svg4"
sodipodi:docname="ShieldIconWhite.svg"
inkscape:version="1.1.2 (0a00cf5339, 2022-02-04)"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<defs
id="defs8" />
<sodipodi:namedview
id="namedview6"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageshadow="2"
inkscape:pageopacity="0.0"
inkscape:pagecheckerboard="0"
showgrid="false"
inkscape:zoom="36.375"
inkscape:cx="11.986254"
inkscape:cy="11.931271"
inkscape:window-width="3072"
inkscape:window-height="1653"
inkscape:window-x="0"
inkscape:window-y="38"
inkscape:window-maximized="1"
inkscape:current-layer="svg4" />
<path
id="path2"
d="M 12,0 C 8.629,2.866 6.516,3 3,3 V 14.535156 C 3,19.138156 6.203,20.339 12,24 c 5.797,-3.661 9,-4.861844 9,-9.464844 V 3 C 17.484,3 15.371,2.866 12,0 Z m 0,2.5449219 c 2.5,1.805 4.554,2.2920156 7,2.4160156 v 9.5742185 c 0,3.042 -1.687,3.826422 -7,7.107422 -5.31,-3.277 -7,-4.065422 -7,-7.107422 V 4.9609375 c 2.446,-0.124 4.5,-0.6110156 7,-2.4160156 z m 1.197266,3.5625 c 0.006,0.00381 0.01163,0.00783 0.01758,0.011719 0.0024,7.206e-4 0.0054,-6.856e-4 0.0078,0 -0.0096,-0.00503 -0.01916,-0.00966 -0.02539,-0.011719 z m 3.408203,1.0058593 c 0.0047,-0.015517 -0.01348,0.029233 -0.01758,0.044922 h 0.002 c 0.0027,-0.00527 -2.63e-4,0.00745 0.01563,-0.044922 z m 0.320312,6.6621098 c -0.0035,7.3e-4 -0.0057,0.0033 -0.0078,0.0059 0.02415,9.71e-4 0.04809,0.0029 0.07227,0.0039 -0.01904,-1.8e-5 -0.04805,-0.01309 -0.06445,-0.0098 z m -3.470703,0.273437 c -8.82e-4,0.0076 -0.0011,0.01584 -0.002,0.02344 h 0.002 c 2.85e-4,-0.0067 -2.83e-4,-0.0166 0,-0.02344 z" />
<path
id="path862"
style="fill:#ececec;fill-opacity:0.00325377;stroke-width:0.0274914"
d="M 12,0.02929688 11.564453,0.37890625 C 9.500132,2.0387502 7.8302749,2.7418641 5.484375,2.9414062 5.1853184,2.9668443 3.6765234,3.0209443 3.1816406,3.0234375 h -0.171875 l 0.00781,6.1386719 0.00781,6.1367186 0.0625,0.384766 c 0.348649,2.163368 1.3772179,3.489654 4.1152344,5.30664 0.6718068,0.44582 0.9710602,0.633641 2.818359,1.765625 0.642611,0.393778 1.347163,0.827062 1.566407,0.964844 0.219244,0.137781 0.411074,0.246334 0.427734,0.240235 0.01666,-0.0061 0.265035,-0.156424 0.550781,-0.333985 0.285746,-0.177563 1.063224,-0.656522 1.728516,-1.064453 2.957236,-1.813262 3.819382,-2.413532 4.738281,-3.302734 1.092429,-1.057125 1.638803,-2.096892 1.878906,-3.576172 l 0.0625,-0.384766 0.0078,-6.1347655 0.0078,-6.1328125 -0.679687,-0.017578 C 18.444818,2.9689575 17.63161,2.8876994 16.695312,2.6523438 15.249704,2.288963 13.968816,1.6064186 12.443359,0.38476562 Z m 0,2.49804692 0.294922,0.203125 c 1.500631,1.0339259 2.926098,1.6539764 4.501953,1.9570312 0.657322,0.1264108 0.997265,0.1678352 2.001953,0.2480469 l 0.212891,0.017578 -0.0098,5.160156 -0.0078,5.158203 -0.06055,0.3125 c -0.294439,1.521988 -1.138946,2.443807 -3.771485,4.119141 -0.355326,0.226128 -1.212742,0.759712 -1.904297,1.185547 -0.691553,0.425836 -1.259671,0.772684 -1.263671,0.771484 -0.02871,-0.0084 -2.7780369,-1.714743 -3.2851566,-2.039062 C 6.196037,18.01392 5.3666312,17.096848 5.0664062,15.587891 l -0.0625,-0.316407 -0.00781,-5.158203 L 4.9882812,4.9550781 5.1738281,4.9375 C 5.2762692,4.9287454 5.4652277,4.915194 5.59375,4.90625 5.9303645,4.8828242 6.6894945,4.7876482 7.0097656,4.7285156 8.6941909,4.4175151 10.104629,3.8222557 11.621094,2.7851562 Z" />
<path
id="path1012"
style="fill:#333333;fill-opacity:0.00325377;stroke-width:0.0274914"
d="M 12,0.02929688 11.564453,0.37890625 C 9.500132,2.0387502 7.8302749,2.7418641 5.484375,2.9414062 5.1853184,2.9668443 3.6765234,3.0209443 3.1816406,3.0234375 h -0.171875 l 0.00781,6.1386719 0.00781,6.1367186 0.0625,0.384766 c 0.348649,2.163368 1.3772179,3.489654 4.1152344,5.30664 0.6718068,0.44582 0.9710602,0.633641 2.818359,1.765625 0.642611,0.393778 1.347163,0.827062 1.566407,0.964844 0.219244,0.137781 0.411074,0.246334 0.427734,0.240235 0.01666,-0.0061 0.265035,-0.156424 0.550781,-0.333985 0.285746,-0.177563 1.063224,-0.656522 1.728516,-1.064453 2.957236,-1.813262 3.819382,-2.413532 4.738281,-3.302734 1.092429,-1.057125 1.638803,-2.096892 1.878906,-3.576172 l 0.0625,-0.384766 0.0078,-6.1347655 0.0078,-6.1328125 -0.679687,-0.017578 C 18.444818,2.9689575 17.63161,2.8876994 16.695312,2.6523438 15.249704,2.288963 13.968816,1.6064186 12.443359,0.38476562 Z m 0,2.49804692 0.294922,0.203125 c 1.500631,1.0339259 2.926098,1.6539764 4.501953,1.9570312 0.657322,0.1264108 0.997265,0.1678352 2.001953,0.2480469 l 0.212891,0.017578 -0.0098,5.160156 -0.0078,5.158203 -0.06055,0.3125 c -0.294439,1.521988 -1.138946,2.443807 -3.771485,4.119141 -0.355326,0.226128 -1.212742,0.759712 -1.904297,1.185547 -0.691553,0.425836 -1.259671,0.772684 -1.263671,0.771484 -0.02871,-0.0084 -2.7780369,-1.714743 -3.2851566,-2.039062 C 6.196037,18.01392 5.3666312,17.096848 5.0664062,15.587891 l -0.0625,-0.316407 -0.00781,-5.158203 L 4.9882812,4.9550781 5.1738281,4.9375 C 5.2762692,4.9287454 5.4652277,4.915194 5.59375,4.90625 5.9303645,4.8828242 6.6894945,4.7876482 7.0097656,4.7285156 8.6941909,4.4175151 10.104629,3.8222557 11.621094,2.7851562 Z" />
<path
id="path1162"
style="fill:#333333;fill-opacity:0.00325377;stroke-width:0.0274914"
d="M 12,0.02929688 11.564453,0.37890625 C 9.500132,2.0387502 7.8302749,2.7418641 5.484375,2.9414062 5.1853184,2.9668443 3.6765234,3.0209443 3.1816406,3.0234375 h -0.171875 l 0.00781,6.1386719 0.00781,6.1367186 0.0625,0.384766 c 0.348649,2.163368 1.3772179,3.489654 4.1152344,5.30664 0.6718068,0.44582 0.9710602,0.633641 2.818359,1.765625 0.642611,0.393778 1.347163,0.827062 1.566407,0.964844 0.219244,0.137781 0.411074,0.246334 0.427734,0.240235 0.01666,-0.0061 0.265035,-0.156424 0.550781,-0.333985 0.285746,-0.177563 1.063224,-0.656522 1.728516,-1.064453 2.957236,-1.813262 3.819382,-2.413532 4.738281,-3.302734 1.092429,-1.057125 1.638803,-2.096892 1.878906,-3.576172 l 0.0625,-0.384766 0.0078,-6.1347655 0.0078,-6.1328125 -0.679687,-0.017578 C 18.444818,2.9689575 17.63161,2.8876994 16.695312,2.6523438 15.249704,2.288963 13.968816,1.6064186 12.443359,0.38476562 Z m 0,2.49804692 0.294922,0.203125 c 1.500631,1.0339259 2.926098,1.6539764 4.501953,1.9570312 0.657322,0.1264108 0.997265,0.1678352 2.001953,0.2480469 l 0.212891,0.017578 -0.0098,5.160156 -0.0078,5.158203 -0.06055,0.3125 c -0.294439,1.521988 -1.138946,2.443807 -3.771485,4.119141 -0.355326,0.226128 -1.212742,0.759712 -1.904297,1.185547 -0.691553,0.425836 -1.259671,0.772684 -1.263671,0.771484 -0.02871,-0.0084 -2.7780369,-1.714743 -3.2851566,-2.039062 C 6.196037,18.01392 5.3666312,17.096848 5.0664062,15.587891 l -0.0625,-0.316407 -0.00781,-5.158203 L 4.9882812,4.9550781 5.1738281,4.9375 C 5.2762692,4.9287454 5.4652277,4.915194 5.59375,4.90625 5.9303645,4.8828242 6.6894945,4.7876482 7.0097656,4.7285156 8.6941909,4.4175151 10.104629,3.8222557 11.621094,2.7851562 Z" />
<path
id="path1201"
style="fill:#000000;fill-opacity:1;stroke-width:0.0274914"
d="M 12,0.02929688 11.564453,0.37890625 C 9.500132,2.0387502 7.8302749,2.7418641 5.484375,2.9414062 5.1853184,2.9668443 3.6765234,3.0209443 3.1816406,3.0234375 h -0.171875 l 0.00781,6.1386719 0.00781,6.1367186 0.0625,0.384766 c 0.348649,2.163368 1.3772179,3.489654 4.1152344,5.30664 0.6718068,0.44582 0.9710602,0.633641 2.818359,1.765625 0.642611,0.393778 1.347163,0.827062 1.566407,0.964844 0.219244,0.137781 0.411074,0.246334 0.427734,0.240235 0.01666,-0.0061 0.265035,-0.156424 0.550781,-0.333985 0.285746,-0.177563 1.063224,-0.656522 1.728516,-1.064453 2.957236,-1.813262 3.819382,-2.413532 4.738281,-3.302734 1.092429,-1.057125 1.638803,-2.096892 1.878906,-3.576172 l 0.0625,-0.384766 0.0078,-6.1347655 0.0078,-6.1328125 -0.679687,-0.017578 C 18.444818,2.9689575 17.63161,2.8876994 16.695312,2.6523438 15.249704,2.288963 13.968816,1.6064186 12.443359,0.38476562 Z m 0,2.49804692 0.294922,0.203125 c 1.500631,1.0339259 2.926098,1.6539764 4.501953,1.9570312 0.657322,0.1264108 0.997265,0.1678352 2.001953,0.2480469 l 0.212891,0.017578 -0.0098,5.160156 -0.0078,5.158203 -0.06055,0.3125 c -0.294439,1.521988 -1.138946,2.443807 -3.771485,4.119141 -0.355326,0.226128 -1.212742,0.759712 -1.904297,1.185547 -0.691553,0.425836 -1.259671,0.772684 -1.263671,0.771484 -0.02871,-0.0084 -2.7780369,-1.714743 -3.2851566,-2.039062 C 6.196037,18.01392 5.3666312,17.096848 5.0664062,15.587891 l -0.0625,-0.316407 -0.00781,-5.158203 L 4.9882812,4.9550781 5.1738281,4.9375 C 5.2762692,4.9287454 5.4652277,4.915194 5.59375,4.90625 5.9303645,4.8828242 6.6894945,4.7876482 7.0097656,4.7285156 8.6941909,4.4175151 10.104629,3.8222557 11.621094,2.7851562 Z" />
<path
id="path3032"
style="fill:#ffffff;fill-opacity:1;stroke-width:0.0274914"
d="m 12,0.02929688 -0.419922,0.3359375 C 9.484323,2.0462713 7.8347307,2.7434544 5.484375,2.9414062 5.1832649,2.9667668 3.6596148,3.0212547 3.1816406,3.0234375 h -0.171875 l 0.00195,5.9179687 c 3.755e-4,3.5633398 0.011283,6.0551098 0.027344,6.2617188 0.034612,0.445251 0.090628,0.781314 0.2050781,1.222656 0.4446659,1.71471 1.5221873,2.952059 4,4.591797 0.6602243,0.436915 0.924661,0.602521 3.2500004,2.03125 0.631272,0.387866 1.225812,0.754501 1.320312,0.814453 0.0945,0.05995 0.1792,0.109238 0.1875,0.109375 0.0083,1.44e-4 0.224208,-0.132396 0.480469,-0.292968 0.256261,-0.160576 0.910748,-0.563457 1.455078,-0.896485 3.356165,-2.053343 4.210065,-2.64965 5.169922,-3.607422 1.176066,-1.173512 1.729293,-2.358049 1.855469,-3.980469 0.01541,-0.198192 0.02502,-2.768554 0.02539,-6.2539058 l 0.002,-5.9179687 H 20.818359 C 20.323842,3.0209355 18.814421,2.9668222 18.515625,2.9414062 16.160899,2.7411136 14.514931,2.0456718 12.419922,0.36523438 Z m 0,2.50000002 0.378906,0.2578125 c 1.772851,1.2082095 3.432116,1.8343811 5.462891,2.0625 0.308268,0.034629 1.048457,0.099299 1.148437,0.099609 0.01175,3.65e-5 0.01672,2.3213242 0.01172,5.1601562 -0.0091,5.140868 -0.0079,5.163648 -0.06641,5.464844 -0.238773,1.22871 -0.850965,2.063485 -2.289063,3.125 -0.645405,0.476398 -1.508998,1.032925 -3.636718,2.341797 -0.556291,0.342204 -1.014379,0.62034 -1.017578,0.61914 -0.01162,-0.0043 -1.679941,-1.034411 -2.4531255,-1.515625 C 7.8039892,19.064647 6.9767998,18.472105 6.3261719,17.84375 5.6172417,17.159089 5.2497834,16.496412 5.0664062,15.578125 l -0.0625,-0.306641 -0.00781,-5.162109 c -0.00447,-2.8388324 0.00192,-5.1601014 0.013672,-5.1601562 0.011756,-6.1e-5 0.1945661,-0.014 0.40625,-0.029297 2.4512,-0.1771311 4.2342814,-0.7897035 6.2050784,-2.1328125 z" />
</svg>

After

Width:  |  Height:  |  Size: 11 KiB

@@ -7,6 +7,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';
interface UnitRenderConfig {
icon: string;
@@ -32,6 +33,11 @@ export class StructureLayer implements Layer {
icon: missileSiloIcon,
borderRadius: 8,
territoryRadius: 6
},
[UnitType.DefensePost]: {
icon: shieldIcon,
borderRadius: 8,
territoryRadius: 6
}
};
-3
View File
@@ -5,8 +5,6 @@ import { bfs, dist, euclDist } from "../../../core/Util";
import { Layer } from "./Layer";
import { EventBus } from "../../../core/EventBus";
import anchorIcon from '../../../../resources/images/AnchorIcon.png';
export class UnitLayer implements Layer {
private canvas: HTMLCanvasElement;
private context: CanvasRenderingContext2D;
@@ -164,7 +162,6 @@ export class UnitLayer implements Layer {
}
}
paintCell(cell: Cell, color: Colord, alpha: number) {
this.clearCell(cell)
this.context.fillStyle = color.alpha(alpha / 255).toRgbString();
@@ -10,6 +10,7 @@ import battleshipIcon from '../../../../../resources/images/BattleshipIconWhite.
import missileSiloIcon from '../../../../../resources/images/MissileSiloIconWhite.svg';
import goldCoinIcon from '../../../../../resources/images/GoldCoinIcon.svg';
import portIcon from '../../../../../resources/images/PortIcon.svg';
import shieldIcon from '../../../../../resources/images/ShieldIconWhite.svg';
import { renderNumber } from '../../Utils';
import { ContextMenuEvent } from '../../../InputHandler';
@@ -25,7 +26,8 @@ const buildTable: BuildItemDisplay[][] = [
{ unitType: UnitType.Destroyer, icon: destroyerIcon },
{ unitType: UnitType.Battleship, icon: battleshipIcon },
{ unitType: UnitType.Port, icon: portIcon },
{ unitType: UnitType.MissileSilo, icon: missileSiloIcon }
{ unitType: UnitType.MissileSilo, icon: missileSiloIcon },
{ unitType: UnitType.DefensePost, icon: shieldIcon }
]
];
+5
View File
@@ -64,6 +64,11 @@ export class DefaultConfig implements Config {
cost: () => 1_000_000,
territoryBound: true
}
case UnitType.DefensePost:
return {
cost: (p: Player) => Math.pow(2, p.units(UnitType.Port).length) * 100_000,
territoryBound: true
}
default:
assertNever(type)
}
+1 -1
View File
@@ -5,7 +5,7 @@ export const devConfig = new class extends DefaultConfig {
unitInfo(type: UnitType): UnitInfo {
const info = super.unitInfo(type)
const oldCost = info.cost
// info.cost = (p: Player) => oldCost(p) / 1000
info.cost = (p: Player) => oldCost(p) / 1000
return info
}
@@ -0,0 +1,43 @@
import { Cell, Execution, MutableGame, MutablePlayer, MutableUnit, PlayerID, Tile, UnitType } from "../game/Game";
export class DefensePostExecution implements Execution {
private player: MutablePlayer
private mg: MutableGame
private post: 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.post == null) {
const spawnTile = this.player.canBuild(UnitType.DefensePost, this.tile)
if (spawnTile == false) {
console.warn('cannot build Defense Post')
this.active = false
return
}
this.post = this.player.buildUnit(UnitType.DefensePost, 0, spawnTile)
}
}
owner(): MutablePlayer {
return null
}
isActive(): boolean {
return this.active
}
activeDuringSpawnPhase(): boolean {
return false
}
}
+3
View File
@@ -22,6 +22,7 @@ import { MissileSiloExecution } from "./MissileSiloExecution";
import { BattleshipExecution } from "./BattleshipExecution";
import { PathFinder } from "../pathfinding/PathFinding";
import { WorkerClient } from "../worker/WorkerClient";
import { DefensePostExecution } from "./DefensePostExecution";
@@ -97,6 +98,8 @@ export class Executor {
return new PortExecution(intent.player, new Cell(intent.x, intent.y), this.workerClient)
case UnitType.MissileSilo:
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))
default:
throw Error(`unit type ${intent.unit} not supported`)
}
+1
View File
@@ -31,6 +31,7 @@ export class PortExecution implements Execution {
tick(ticks: number): void {
if (this.port == null) {
// TODO: use canBuild
const tile = this.mg.tile(this.cell)
const player = this.mg.player(this._owner)
if (!player.canBuild(UnitType.Port, tile)) {
+1
View File
@@ -39,6 +39,7 @@ export enum UnitType {
HydrogenBomb = "Hydrogen Bomb",
TradeShip = "Trade Ship",
MissileSilo = "Missile Silo",
DefensePost = "Defense Post"
}
export class Nation {
+4 -2
View File
@@ -365,7 +365,9 @@ export class PlayerImpl implements MutablePlayer {
case UnitType.Shell:
return targetTile
case UnitType.MissileSilo:
return this.missileSiloSpawn(targetTile)
return this.landBasedStructureSpawn(targetTile)
case UnitType.DefensePost:
return this.landBasedStructureSpawn(targetTile)
case UnitType.TransportShip:
return this.transportShipSpawn(targetTile)
case UnitType.TradeShip:
@@ -406,7 +408,7 @@ export class PlayerImpl implements MutablePlayer {
return spawns[0].tile()
}
missileSiloSpawn(tile: Tile): Tile | false {
landBasedStructureSpawn(tile: Tile): Tile | false {
if (tile.owner() != this) {
return false
}