working on port

This commit is contained in:
Evan
2024-11-12 20:49:24 -08:00
parent 49b35b0e45
commit 4236a580e3
9 changed files with 111 additions and 23 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 143 B

+40
View File
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
version="1.1"
x="0px"
y="0px"
viewBox="0 0 100 125"
enable-background="new 0 0 100 100"
xml:space="preserve"
id="svg12"
sodipodi:docname="PortIcon.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="defs16" /><sodipodi:namedview
id="namedview14"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageshadow="2"
inkscape:pageopacity="0.0"
inkscape:pagecheckerboard="0"
showgrid="false"
inkscape:zoom="6.984"
inkscape:cx="15.463918"
inkscape:cy="62.142039"
inkscape:window-width="3072"
inkscape:window-height="1653"
inkscape:window-x="0"
inkscape:window-y="38"
inkscape:window-maximized="1"
inkscape:current-layer="svg12" /><g
id="g6"><g
id="g4"><path
d="M86.946,70.119l-2.417-15.098c-0.286-1.419-1.511-2.495-2.982-2.495c-0.899,0-1.687,0.385-2.268,0.997L68.104,63.997 c-0.176,0.156-0.352,0.338-0.515,0.56c-1.049,1.433-0.749,3.465,0.684,4.527c0.273,0.215,0.573,0.345,0.866,0.462l2.808,0.931 c-2.697,7.641-9.313,13.45-17.417,15.059l0.014-45.638h5.992c1.889,0,3.412-1.538,3.412-3.426c0-1.875-1.523-3.413-3.412-3.413 h-5.992v-6.78c3.979-1.687,6.721-5.634,6.721-10.206C61.264,9.95,56.314,5,50.192,5c-6.097,0-11.073,4.95-11.073,11.073 c0,4.578,2.847,8.52,6.8,10.206l0.007,6.78h-6.468c-1.882,0-3.413,1.538-3.413,3.413c0,1.889,1.531,3.426,3.413,3.426h6.468 l0.021,45.71c-8.292-1.485-15.15-7.354-17.926-15.131l2.827-0.931c0.299-0.117,0.6-0.247,0.879-0.456 c1.427-1.067,1.753-3.1,0.671-4.533c-0.155-0.222-0.313-0.404-0.508-0.554L20.706,53.524c-0.553-0.612-1.361-0.997-2.246-0.997 c-1.486,0-2.743,1.075-3.009,2.495l-2.424,15.098c-0.053,0.241-0.064,0.508-0.064,0.762c0,1.791,1.446,3.236,3.229,3.236 c0.339,0,0.658-0.032,0.959-0.137l2.624-0.853C23.956,85.816,35.901,95,49.997,95c14.094,0,26.053-9.184,30.221-21.891 l2.619,0.872c0.299,0.105,0.618,0.137,0.963,0.137c1.785,0,3.237-1.446,3.237-3.236C87.037,70.627,87.012,70.36,86.946,70.119 M45.659,16.073c0-2.521,2.044-4.553,4.533-4.553c2.527,0,4.552,2.032,4.552,4.553c0,2.514-2.024,4.559-4.552,4.559 C47.703,20.632,45.659,18.586,45.659,16.073"
id="path2" /></g></g><path
style="fill:#ffffff;stroke:none;stroke-width:0.143184"
d="M 46.821306,94.770829 C 37.149181,93.798182 28.293166,88.256973 23.04965,79.896907 c -0.868866,-1.385288 -2.385574,-4.487112 -2.870545,-5.870561 -0.179443,-0.511884 -0.334071,-0.944343 -0.343618,-0.96102 -0.0095,-0.01668 -0.705224,0.192731 -1.545948,0.46535 -0.840723,0.272619 -1.804312,0.494255 -2.141309,0.492526 -1.598809,-0.0082 -3.122304,-1.547171 -3.115278,-3.146913 8.64e-4,-0.196879 0.574575,-3.918388 1.274912,-8.270022 1.419295,-8.818969 1.428076,-8.850837 2.627499,-9.536632 0.834583,-0.477189 1.483957,-0.563323 2.337029,-0.309989 0.644845,0.191499 1.336272,0.793564 6.866372,5.978939 4.549564,4.26596 6.233135,5.932201 6.471488,6.40487 0.603214,1.196211 0.325525,2.693184 -0.677921,3.654548 -0.288018,0.275937 -1.002559,0.607386 -2.183926,1.013042 -2.007091,0.68919 -1.921853,0.529349 -1.189152,2.229934 2.313522,5.369652 7.064022,9.988932 12.577448,12.230032 1.263767,0.513697 3.384288,1.159414 4.275471,1.30192 l 0.550027,0.08795 V 62.733077 39.805269 H 42.37799 c -3.958889,0 -4.236614,-0.04887 -5.126792,-0.902159 -0.76147,-0.729916 -1.085823,-1.473414 -1.081006,-2.477941 0.0071,-1.483668 0.947583,-2.699422 2.43431,-3.146861 0.49772,-0.149791 1.545965,-0.202707 4.01562,-0.202707 h 3.342077 V 29.652118 26.228633 L 44.85252,25.624122 c -0.793899,-0.432485 -1.482722,-0.979822 -2.420583,-1.923389 -1.146297,-1.15327 -1.401076,-1.505996 -2.029023,-2.809061 -0.858345,-1.781165 -1.170382,-3.086543 -1.170382,-4.896174 0,-6.4184795 5.839733,-11.6186738 12.164919,-10.8326779 2.656895,0.3301574 4.668838,1.3296881 6.615711,3.286675 1.070143,1.0757025 1.339007,1.4513238 1.957431,2.7346549 0.865772,1.796619 1.169155,3.085051 1.169155,4.965255 0,4.023175 -2.191435,7.679165 -5.755536,9.602011 l -0.969271,0.522925 -0.0024,3.389446 -0.0024,3.389446 3.472222,0.04702 c 3.946037,0.05344 4.168331,0.108713 5.177124,1.287261 1.316051,1.53751 0.926562,3.821223 -0.837885,4.912821 l -0.700444,0.433339 -3.555509,0.04279 -3.555508,0.0428 v 22.902508 c 0,12.596381 0.04833,22.902346 0.107388,22.902148 0.332248,-0.0011 2.935079,-0.780331 4.075018,-1.219944 5.752163,-2.218302 10.721311,-7.144396 13.059805,-12.946652 0.204466,-0.507318 0.322918,-0.966456 0.263226,-1.020307 -0.05969,-0.05385 -0.65621,-0.274921 -1.325597,-0.491268 -1.73484,-0.560706 -2.51001,-1.013168 -2.998016,-1.749923 -0.680235,-1.026966 -0.727607,-2.0483 -0.14813,-3.19361 0.309132,-0.610985 12.085183,-11.683542 12.854449,-12.08653 1.199252,-0.628243 2.81487,-0.181005 3.651625,1.010847 0.392869,0.559594 0.481176,1.003292 1.695561,8.519473 0.875547,5.419011 1.264717,8.190005 1.229335,8.753186 -0.06941,1.104804 -0.613524,1.897274 -1.670778,2.433394 -1.027413,0.520988 -1.635513,0.502208 -3.442467,-0.106313 -0.816705,-0.275039 -1.512424,-0.472563 -1.546044,-0.438944 -0.03362,0.03362 -0.379938,0.854657 -0.769596,1.824527 -2.13365,5.310705 -5.61865,9.924534 -10.123033,13.401993 -6.338429,4.893379 -14.56767,7.254819 -22.501513,6.456977 z m 4.86827,-74.330261 c 1.140586,-0.346728 2.230937,-1.344337 2.770928,-2.535241 0.21803,-0.480845 0.29704,-0.95557 0.301498,-1.811516 0.0055,-1.049248 -0.04177,-1.253646 -0.495106,-2.142377 -1.123467,-2.202486 -3.642798,-3.073429 -5.980881,-2.067613 -0.987511,0.424816 -2.068224,1.59611 -2.409954,2.611949 -1.248434,3.711132 2.053637,7.087771 5.813515,5.944798 z"
id="path257" /></svg>

After

Width:  |  Height:  |  Size: 5.7 KiB

+8 -6
View File
@@ -1,7 +1,7 @@
import { Config } from "../core/configuration/Config"
import { EventBus, GameEvent } from "../core/EventBus"
import { AllianceRequest, AllPlayers, Cell, Player, PlayerID, PlayerType, Tile } from "../core/game/Game"
import { ClientID, ClientIntentMessageSchema, ClientJoinMessageSchema, ClientLeaveMessageSchema, CreateDestroyerIntent, GameID, Intent, ServerMessage, ServerMessageSchema } from "../core/Schemas"
import { AllianceRequest, AllPlayers, Cell, Item, Player, PlayerID, PlayerType, Tile, UnitType } from "../core/game/Game"
import { ClientID, ClientIntentMessageSchema, ClientJoinMessageSchema, ClientLeaveMessageSchema, BuildUnitIntentSchema, GameID, Intent, ServerMessage, ServerMessageSchema } from "../core/Schemas"
import { LocalServer } from "./LocalServer"
@@ -47,8 +47,9 @@ export class SendBoatAttackIntentEvent implements GameEvent {
) { }
}
export class SendCreateDestroyerIntentEvent implements GameEvent {
export class BuildUnitIntentEvent implements GameEvent {
constructor(
public readonly unit: UnitType,
public readonly cell: Cell,
) { }
}
@@ -121,7 +122,7 @@ export class Transport {
this.eventBus.on(SendDonateIntentEvent, (e) => this.onSendDonateIntent(e))
this.eventBus.on(SendNukeIntentEvent, (e) => this.onSendNukeIntent(e))
this.eventBus.on(SendSetTargetTroopRatioEvent, (e) => this.onSendSetTargetTroopRatioEvent(e))
this.eventBus.on(SendCreateDestroyerIntentEvent, (e) => this.onCreateDestroyerIntent(e))
this.eventBus.on(BuildUnitIntentEvent, (e) => this.onCreateDestroyerIntent(e))
}
connect(onconnect: () => void, onmessage: (message: ServerMessage) => void) {
@@ -321,11 +322,12 @@ export class Transport {
})
}
private onCreateDestroyerIntent(event: SendCreateDestroyerIntentEvent) {
private onCreateDestroyerIntent(event: BuildUnitIntentEvent) {
this.sendIntent({
type: "create_destroyer",
type: "build_unit",
clientID: this.clientID,
player: this.playerID,
unit: event.unit,
x: event.cell.x,
y: event.cell.y,
})
+2
View File
@@ -5,6 +5,8 @@ import { bfs, dist, euclDist } from "../../../core/Util";
import { Layer } from "./Layer";
import { EventBus } from "../../../core/EventBus";
import anchorIncon from '../../../../../resources/images/AnchorIcon.png';
export class UnitLayer implements Layer {
private canvas: HTMLCanvasElement
private context: CanvasRenderingContext2D
@@ -1,11 +1,12 @@
import { LitElement, html, css } from 'lit';
import { customElement, state } from 'lit/decorators.js';
import { EventBus } from '../../../../core/EventBus';
import { Cell, Game, Item, Items, Player } from '../../../../core/game/Game';
import { SendCreateDestroyerIntentEvent, SendNukeIntentEvent } from '../../../Transport';
import { Cell, Game, Item, Items, Player, UnitType } from '../../../../core/game/Game';
import { BuildUnitIntentEvent as BuildItemIntentEvent, BuildUnitIntentEvent, SendNukeIntentEvent } from '../../../Transport';
import nukeIcon from '../../../../../resources/images/NukeIconWhite.svg';
import destroyerIcon from '../../../../../resources/images/DestroyerIconWhite.svg';
import goldCoinIcon from '../../../../../resources/images/GoldCoinIcon.svg';
import portIcon from '../../../../../resources/images/PortIcon.svg';
import { renderNumber } from '../../Utils';
import { ContextMenuEvent } from '../../../InputHandler';
@@ -18,7 +19,7 @@ const buildTable: BuildItem[][] = [
[
{ item: Items.Nuke, icon: nukeIcon },
{ item: Items.Destroyer, icon: destroyerIcon },
// { id: 'battleship', name: 'Battleship', icon: '🚢', cost: 500, buildTime: 20 }
{ item: Items.Port, icon: portIcon }
]
];
@@ -154,8 +155,9 @@ export class BuildMenu extends LitElement {
this.eventBus.emit(new SendNukeIntentEvent(this.myPlayer, this.clickedCell, null))
break
case "Destroyer":
this.eventBus.emit(new SendCreateDestroyerIntentEvent(this.clickedCell))
this.eventBus.emit(new BuildUnitIntentEvent(UnitType.Destroyer, this.clickedCell))
case "Port":
this.eventBus.emit(new BuildUnitIntentEvent(UnitType.Port, this.clickedCell))
}
this.hideMenu()
};
+8 -7
View File
@@ -1,5 +1,5 @@
import { z } from 'zod';
import { Difficulty, GameMap, PlayerType } from './game/Game';
import { Difficulty, GameMap, PlayerType, UnitType } from './game/Game';
export type GameID = string
export type ClientID = string
@@ -15,7 +15,7 @@ export type Intent = SpawnIntent
| DonateIntent
| NukeIntent
| TargetTroopRatioIntent
| CreateDestroyerIntent
| BuildUnitIntent
export type AttackIntent = z.infer<typeof AttackIntentSchema>
export type SpawnIntent = z.infer<typeof SpawnIntentSchema>
@@ -28,7 +28,7 @@ export type EmojiIntent = z.infer<typeof EmojiIntentSchema>
export type DonateIntent = z.infer<typeof DonateIntentSchema>
export type NukeIntent = z.infer<typeof NukeIntentSchema>
export type TargetTroopRatioIntent = z.infer<typeof TargetTroopRatioIntentSchema>
export type CreateDestroyerIntent = z.infer<typeof CreateDestroyerIntentSchema>
export type BuildUnitIntent = z.infer<typeof BuildUnitIntentSchema>
export type Turn = z.infer<typeof TurnSchema>
export type GameConfig = z.infer<typeof GameConfigSchema>
@@ -69,7 +69,7 @@ const EmojiSchema = z.string().refine(
);
// Zod schemas
const BaseIntentSchema = z.object({
type: z.enum(['attack', 'spawn', 'boat', 'name', 'targetPlayer', 'emoji', 'nuke', 'troop_ratio', 'create_destroyer']),
type: z.enum(['attack', 'spawn', 'boat', 'name', 'targetPlayer', 'emoji', 'nuke', 'troop_ratio', 'build_unit']),
clientID: z.string(),
});
@@ -161,9 +161,10 @@ export const TargetTroopRatioIntentSchema = BaseIntentSchema.extend({
ratio: z.number().min(0).max(1),
})
export const CreateDestroyerIntentSchema = BaseIntentSchema.extend({
type: z.literal('create_destroyer'),
export const BuildUnitIntentSchema = BaseIntentSchema.extend({
type: z.literal('build_unit'),
player: z.string(),
unit: z.nativeEnum(UnitType),
x: z.number(),
y: z.number(),
})
@@ -180,7 +181,7 @@ const IntentSchema = z.union([
DonateIntentSchema,
NukeIntentSchema,
TargetTroopRatioIntentSchema,
CreateDestroyerIntentSchema,
BuildUnitIntentSchema,
]);
const TurnSchema = z.object({
+10 -2
View File
@@ -1,4 +1,4 @@
import { Cell, Execution, MutableGame, Game, MutablePlayer, PlayerInfo, TerraNullius, Tile, PlayerType, Alliance, AllianceRequestReplyEvent, Difficulty } from "../game/Game";
import { Cell, Execution, MutableGame, Game, MutablePlayer, PlayerInfo, TerraNullius, Tile, PlayerType, Alliance, AllianceRequestReplyEvent, Difficulty, UnitType } from "../game/Game";
import { AttackIntent, BoatAttackIntentSchema, GameID, Intent, Turn } from "../Schemas";
import { AttackExecution } from "./AttackExecution";
import { SpawnExecution } from "./SpawnExecution";
@@ -17,6 +17,7 @@ import { DonateExecution } from "./DonateExecution";
import { NukeExecution } from "./NukeExecution";
import { SetTargetTroopRatioExecution } from "./SetTargetTroopRatioExecution";
import { DestroyerExecution } from "./DestroyerExecution";
import { PortExecution } from "./PortExecution";
@@ -81,8 +82,15 @@ export class Executor {
return new NukeExecution(intent.sender, new Cell(intent.x, intent.y), intent.magnitude);
case "troop_ratio":
return new SetTargetTroopRatioExecution(intent.player, intent.ratio);
case "create_destroyer":
case "build_unit":
switch (intent.unit) {
case UnitType.Destroyer:
return new DestroyerExecution(intent.player, new Cell(intent.x, intent.y))
case UnitType.Port:
return new PortExecution(intent.player, new Cell(intent.x, intent.y))
default:
throw Error(`unit type ${intent.unit} not supported`)
}
default:
throw new Error(`intent type ${intent} not found`);
}
+31
View File
@@ -0,0 +1,31 @@
import { AllPlayers, Cell, Execution, MutableGame, MutablePlayer, PlayerID } from "../game/Game";
export class PortExecution implements Execution {
private active = true
constructor(
private _owner: PlayerID,
private cell: Cell
) { }
init(mg: MutableGame, ticks: number): void {
}
tick(ticks: number): void {
}
owner(): MutablePlayer {
return null
}
isActive(): boolean {
return this.active
}
activeDuringSpawnPhase(): boolean {
return false
}
}
+4 -2
View File
@@ -27,7 +27,8 @@ export enum GameMap {
export enum UnitType {
TransportShip,
Destroyer
Destroyer,
Port
}
export class Item {
@@ -36,7 +37,8 @@ export class Item {
export const Items = {
Nuke: new Item("Nuke", 1_000_000),
Destroyer: new Item("Destroyer", 10)
Destroyer: new Item("Destroyer", 10),
Port: new Item("Port", 10)
} as const;
export class Nation {