balancing

This commit is contained in:
Bastian Wagner 2025-04-27 09:54:47 +02:00
parent 01153a1db3
commit c0ec36ba82
11 changed files with 171 additions and 98 deletions

View File

@ -41,19 +41,19 @@
<div>🍽️ Verbrauch:</div>
<ul>
@for (item of consumedItems; track $index) {
<li>{{ item.type }}: {{ item.demandRate * planet.population | number:'0.0-1' }}/s</li>
<li>{{ item.type }}: {{ item.demandRate * planet.population | number:'0.0-2' }}/s</li>
}
</ul>
</div>
<!-- <div class="ui-section">
<div class="ui-section">
<div>📦 Anfrage:</div>
<ul>
@for (item of requested; track $index) {
<li>{{ item.type }}: {{ item.amount | number:'0.0-1' }}/s</li>
}
</ul>
</div> -->
</div>
@if (goodsInTransit.length > 0) {
<div class="ui-section">
@ -92,6 +92,7 @@
<button class="button" (click)="upgradeProduction()" [disabled]="!canUpgradeProduction"
matTooltip="Kosten: {{this.planet.productionLvlUpgradeCost | number}} Credits">Produktion aufwerten</button>
<button (click)="buildFactory()" >Fabrik bauen</button>
} @else {
<button class="button" (click)="buildHarbour()"
matTooltip="Baue einen Raumhafen um den Planeten anfliegen zu können."

View File

@ -111,5 +111,8 @@ export class PlanetDialogComponent {
return this.planet.requestedGoods;
}
buildFactory() {
this.planet.buildFactory();
}
}

View File

@ -5,6 +5,7 @@ import { CdkDrag, CdkDragDrop, CdkDragHandle, CdkDropList, moveItemInArray, tran
import { Planet } from '../../../model/planet.model';
import { ShipConfig } from '../../../model/ships/ship.model';
import { FormsModule } from '@angular/forms';
import { SHIP_DATA } from '../../../model/ships/ship.type';
@Component({
selector: 'app-buy',
@ -18,42 +19,18 @@ export class BuyComponent {
availablePlanets: Planet[] = this.gameService.planets.filter(p => p.hasHarbour);
selectedPlanets: Planet[] = [];
config: ShipConfig = {
name: 'Pioneer-01',
acceleration: 428,
cargoSize: 25,
cost: 0.6,
loadingSpeed: 15,
maxSpeed: 300,
planetRoute: [],
buyCost: 3000,
desciption: 'Ein kleines, schnelles Schiff. Es hat wenig Platz für Ladung, lädt aber schnell und ist sehr wendig.',
texture: 'swift-hauler'
...SHIP_DATA.light,
planetRoute: []
}
config2: ShipConfig = {
name: 'Colony Carrier',
acceleration: 63,
cargoSize: 70,
cost: 1.6,
loadingSpeed: 20,
maxSpeed: 200,
...SHIP_DATA.medium,
planetRoute: [],
buyCost: 8000,
desciption: 'Eine größere Version von der Pioneer-01. Der größere Frachtraum geht zu Lasten der Beschleunigung und Maximalgeschwindigkeit.',
texture: 'colony-carrier'
}
config3: ShipConfig = {
name: 'Industrial Tanker',
acceleration: 8,
cargoSize: 300,
cost: 3.8,
loadingSpeed: 11,
maxSpeed: 600,
planetRoute: [],
buyCost: 14000,
desciption: 'Ein großes behäbiges Schiff. Es wird durchaus schnell, beschleunigt aber sehr langsam und erreicht die Spitzengeschwindigkeit nur selten.',
texture: 'industrial-tanker'
...SHIP_DATA.heavy,
planetRoute: []
}
selectedModel = '1';

View File

@ -9,8 +9,9 @@ export const PLANETCONFIGS: { x: number, y: number, texture: string, config: Pla
config: {
name: 'Terra Nova',
initialGoods: [
{ type: GoodType.Wasser, amount: 10 },
{ type: GoodType.Nahrung, amount: 10, productionBonus: 2.6 },
{ type: GoodType.Wasser, amount: 10, productionBonus: 0.18 },
{ type: GoodType.Nahrung, amount: 10, productionBonus: 2.3 },
{ type: GoodType.Erz, amount: 10, productionBonus: 0 },
]
}
},
@ -21,11 +22,9 @@ export const PLANETCONFIGS: { x: number, y: number, texture: string, config: Pla
config: {
name: 'Mechanica Prime',
initialGoods: [
{ type: GoodType.Wasser, amount: 10 },
{ type: GoodType.Nahrung, amount: 10 },
{ type: GoodType.Metall, amount: 10, productionBonus: 3 },
{ type: GoodType.Bauteile, amount: 10, productionBonus: 1.3 },
{ type: GoodType.Elektronik, amount: 10 }
{ type: GoodType.Wasser, amount: 10, productionBonus: 0.07 },
{ type: GoodType.Nahrung, amount: 10, productionBonus: 0.05 },
{ type: GoodType.Erz, amount: 10, productionBonus: 1.5 },
]
}
},
@ -36,9 +35,9 @@ export const PLANETCONFIGS: { x: number, y: number, texture: string, config: Pla
config: {
name: 'Aqualis',
initialGoods: [
{ type: GoodType.Wasser, amount: 200, productionBonus: 4 },
{ type: GoodType.Nahrung, amount: 10 },
{ type: GoodType.Treibstoff, amount: 10 }
{ type: GoodType.Wasser, amount: 10, productionBonus: 2.5 },
{ type: GoodType.Nahrung, amount: 10, productionBonus: 0.06 },
{ type: GoodType.Erz, amount: 10, productionBonus: 0.2 }
]
}
},
@ -49,11 +48,9 @@ export const PLANETCONFIGS: { x: number, y: number, texture: string, config: Pla
config: {
name: 'Ferron',
initialGoods: [
{ type: GoodType.Wasser, amount: 10 },
{ type: GoodType.Nahrung, amount: 10 },
{ type: GoodType.Erz, amount: 10, productionBonus: 1.8 },
{ type: GoodType.Metall, amount: 10 },
{ type: GoodType.Treibstoff, amount: 10 }
{ type: GoodType.Wasser, amount: 10, productionBonus: 0.02 },
{ type: GoodType.Nahrung, amount: 10, productionBonus: 0.03 },
{ type: GoodType.Erz, amount: 10, productionBonus: 2.2 }
]
}
},
@ -64,9 +61,9 @@ export const PLANETCONFIGS: { x: number, y: number, texture: string, config: Pla
config: {
name: 'Novus Reach',
initialGoods: [
{ type: GoodType.Nahrung, amount: 10, productionBonus: 1.5 },
{ type: GoodType.Wasser, amount: 10 },
{ type: GoodType.Bauteile, amount: 10 }
{ type: GoodType.Wasser, amount: 10, productionBonus: 1.6 },
{ type: GoodType.Nahrung, amount: 10, productionBonus: 0.07 },
{ type: GoodType.Erz, amount: 10, productionBonus: 0.1 }
]
}
}
@ -78,9 +75,9 @@ export const PLANETCONFIGS: { x: number, y: number, texture: string, config: Pla
config: {
name: 'Volaris',
initialGoods: [
{ type: GoodType.Nahrung, amount: 10 },
{ type: GoodType.Wasser, amount: 10, productionBonus: 1.9 },
{ type: GoodType.Bauteile, amount: 10 }
{ type: GoodType.Wasser, amount: 10, productionBonus: 0.25 },
{ type: GoodType.Nahrung, amount: 10, productionBonus: 2.2 },
{ type: GoodType.Erz, amount: 10, productionBonus: 0 }
]
}
},
@ -91,10 +88,10 @@ export const PLANETCONFIGS: { x: number, y: number, texture: string, config: Pla
config: {
name: 'Ignis Prime',
initialGoods: [
{ type: GoodType.Wasser, amount: 10 },
{ type: GoodType.Nahrung, amount: 10 },
{ type: GoodType.Treibstoff, amount: 10, productionBonus: 0.8 }
{ type: GoodType.Wasser, amount: 10, productionBonus: 1.3 },
{ type: GoodType.Nahrung, amount: 10, productionBonus: 0.06 },
{ type: GoodType.Erz, amount: 10, productionBonus: 0.1 }
]
}
}
},
]

View File

@ -0,0 +1,37 @@
import { GoodConfig, GOODS_DATA } from "../goods/good-config";
import { GoodType } from "../goods/good-type.enum";
import { Planet } from "../planet.model";
export class Factory {
product: GoodConfig;
private type: GoodType;
private planet: Planet;
constructor(config: FactoryConfig) {
this.product = GOODS_DATA[config.type];
this.type = config.type;
this.planet = config.planet;
const existing = this.planet.getGood(this.type);
if (existing) {
existing.productionRate = this.product.baseProduction;
} else {
this.planet.addGood({
amount: 0,
demandRate: this.product.baseDemand,
productionRate: this.product.baseProduction,
productionStorage: this.product.storageLimit,
type: this.type
});
}
}
}
export interface FactoryConfig {
type: GoodType;
planet: Planet;
}

View File

@ -5,14 +5,15 @@ export interface GoodConfig {
baseDemand: number; // pro Sekunde
storageLimit: number;
isRawResource: boolean;
dependsOn?: GoodType[];
}
export const GOODS_DATA: Record<GoodType, GoodConfig> = {
[GoodType.Erz]: { baseProduction: 1.0, baseDemand: 0.005, storageLimit: 200, isRawResource: true },
[GoodType.Wasser]: { baseProduction: 1, baseDemand: 0.0075, storageLimit: 500, isRawResource: true },
[GoodType.Nahrung]: { baseProduction: 1, baseDemand: 0.005, storageLimit: 300, isRawResource: true },
[GoodType.Metall]: { baseProduction: 1, baseDemand: 0.005, storageLimit: 300, isRawResource: false },
[GoodType.Treibstoff]: { baseProduction: 1, baseDemand: 0.002, storageLimit: 150, isRawResource: false },
[GoodType.Elektronik]: { baseProduction: 1, baseDemand: 0.005, storageLimit: 100, isRawResource: false },
[GoodType.Bauteile]: { baseProduction: 1, baseDemand: 0.005, storageLimit: 100, isRawResource: false }
[GoodType.Wasser]: { baseProduction: 1, baseDemand: 0.0012, storageLimit: 500, isRawResource: true },
[GoodType.Nahrung]: { baseProduction: 1, baseDemand: 0.001, storageLimit: 300, isRawResource: true },
[GoodType.Erz]: { baseProduction: 1.0, baseDemand: 0.0005, storageLimit: 200, isRawResource: true },
[GoodType.Metall]: { baseProduction: 0.7, baseDemand: 0.003, storageLimit: 300, isRawResource: false, dependsOn: [GoodType.Erz, GoodType.Wasser] },
[GoodType.Treibstoff]: { baseProduction: 0.5, baseDemand: 0.002, storageLimit: 150, isRawResource: false, dependsOn: [GoodType.Wasser] },
[GoodType.Elektronik]: { baseProduction: 0.3, baseDemand: 0.001, storageLimit: 100, isRawResource: false, dependsOn: [GoodType.Bauteile, GoodType.Treibstoff] },
[GoodType.Bauteile]: { baseProduction: 0.5, baseDemand: 0.0015, storageLimit: 100, isRawResource: false, dependsOn: [GoodType.Metall] }
};

View File

@ -4,14 +4,16 @@ import { GOODS_DATA } from "./goods/good-config";
import { Good } from "./goods/good.interface";
import { Ship } from "./ships/ship.model";
import { GameService } from "../service/game.service";
import { Factory } from "./factories/factory.model";
export class Planet {
public population: number = 100;
public name: string = "";
public image: string;
public updateModifier = 1; // für Simulation
private goods: Map<string, Good> = new Map();
private updateSubscription = interval(1000).subscribe(() => {this.update(1)}); // alle 5s
private updateSubscription = interval(1000).subscribe(() => {this.update(this.updateModifier)}); // alle 5s
public isGrowing: boolean = false;
private populationGrowthRate = 0.002; // Basiswachstum pro Tick (%)
@ -20,9 +22,11 @@ export class Planet {
private productionLevel: Map<GoodType, number> = new Map();
private dockedShips: Ship[] = [];
public dockCapacity: number = 0;
public dockCapacity: number = 1;
private shipsWaitingForDocking: Ship[] = [];
private factory: Factory | undefined;
private gameService: GameService;
hasHarbour = false;
@ -54,10 +58,11 @@ export class Planet {
productionStorage: base.storageLimit
})
});
console.log(this.getAllGoods())
this.updatePopulation(0)
setTimeout(() => {
this.dockCapacity = 1;
this.getStatus();
}, 10000)
}
@ -71,28 +76,28 @@ export class Planet {
}
break;
case GoodType.Bauteile:
if (this.population > 500) {
if (this.population > 700) {
good.demandRate = GOODS_DATA.Bauteile.baseDemand
} else {
good.demandRate = 0;
}
break;
case GoodType.Elektronik:
if (this.population > 700) {
if (this.population > 900) {
good.demandRate = GOODS_DATA.Elektronik.baseDemand
} else {
good.demandRate = 0;
}
break;
case GoodType.Metall:
if (this.population > 750) {
if (this.population > 350) {
good.demandRate = GOODS_DATA.Metall.baseDemand
} else {
good.demandRate = 0;
}
break;
case GoodType.Treibstoff:
if (this.population > 900) {
if (this.population > 500) {
good.demandRate = GOODS_DATA.Treibstoff.baseDemand
} else {
good.demandRate = 0;
@ -103,19 +108,37 @@ export class Planet {
private update(seconds: number): void {
this.goods.forEach((good: Good, key: string) => {
this.adjustPopulationDemands(good)
const base = GOODS_DATA[good.type];
const lvlMultiplier = this.productionLevel.get(good.type) ?? 1;
good.amount += good.productionRate * seconds * lvlMultiplier;
// Min 0
good.amount = Math.max(0, good.amount);
if (good.productionRate && good.productionStorage) {
good.amount = Math.min(good.amount, good.productionStorage)
if (base.isRawResource) {
good.amount += good.productionRate * seconds * lvlMultiplier;
// Min 0
good.amount = Math.max(0, good.amount);
if (good.productionRate && good.productionStorage) {
good.amount = Math.min(good.amount, good.productionStorage)
}
} else {
if (good.productionRate == 0) { return; }
const depends = base.dependsOn;
if (!depends) { return; }
const depending = this.getAllGoods().filter(g => depends.includes(g.type));
const amount = good.productionRate * seconds * lvlMultiplier;
if (depending.some(d => d.amount < seconds * lvlMultiplier)) { return; }
depending.map(d => {
d.amount -= seconds * lvlMultiplier;
});
good.amount += amount;
}
});
this.updatePopulation(seconds)
@ -155,7 +178,7 @@ export class Planet {
get requestedGoods(): TradeInstance[] {
const result: TradeInstance[] = [];
const goods = this.getAllGoods().filter(g => !g.productionRate && g.demandRate);
const goods = this.getAllGoods().filter(g => g.demandRate);
for (let good of goods) {
const demandPerSecond = good.demandRate * this.population;
const demand = this.demandSecondsBuffer * demandPerSecond;
@ -171,7 +194,7 @@ export class Planet {
}
result.push({
amount: demand * 5, // Request 3x buffer amount
amount: demand * 5 - good.amount - inTransit, // Request 3x buffer amount
type: good.type,
target: this.name,
})
@ -181,7 +204,7 @@ export class Planet {
}
get offeredGoods(): TradeInstance[] {
return this.getAllGoods().filter(g => g.productionRate && g.amount).map(g => { return { type: g.type, amount: g.amount - (g.demandRate * this.population * this.demandSecondsBuffer), target: this.name }}).filter(g => g.amount > 0)
return this.getAllGoods().filter(g => g.productionRate && g.amount).map(g => { return { type: g.type, amount: g.amount - (g.demandRate * this.population * (this.demandSecondsBuffer * 1.2)), target: this.name }}).filter(g => g.amount > 0)
}
request(demandedGood: {type: GoodType, amount: number}) {
@ -226,12 +249,6 @@ export class Planet {
}
// if (this.isGrowing) {
// console.log(`[${this.name}] Growing population: ${this.population.toFixed(2)}`);
// } else {
// console.log(`[${this.name}] Shrinking population: ${this.population.toFixed(2)}`);
// }
// Verbrauch abziehen
demands.forEach((amountNeeded, goodType) => {
const good = this.goods.get(goodType);
@ -366,6 +383,27 @@ export class Planet {
return lvl * 1000;
}
buildFactory() {
this.factory = new Factory({
planet: this,
type: GoodType.Elektronik
});
}
public getStatus(): void {
console.log(`[${this.name}]: ${this.isGrowing ? '🚀' : '⬇️'}`);
console.log('Population:', Math.round(this.population));
console.log('Goods:\n', Array.from(this.goods.entries()).map(([type, good]) =>
`${type}: ${Math.round(good.amount)} (Prod: ${good.productionRate}, Demand: ${good.demandRate})`
).join('\n'));
// console.log('Docked Ships:', this.dockedShips.length);
// console.log('Waiting Ships:', this.shipsWaitingForDocking.length);
console.log('Production Levels:', Array.from(this.productionLevel.entries()).map(([type, level]) =>
`${type}: ${level}`
).join(', '));
console.log(`\n\n`)
}
}
export interface PlanetInit {

View File

@ -3,18 +3,10 @@ import { Good } from "../goods/good.interface";
import { Planet, TradeInstance } from "../planet.model";
import { TradeRoute } from "../routes/trade-route.model";
import { GameService } from "../../service/game.service";
import { ShipType } from "./ship.type";
export interface ShipConfig {
name: string;
cargoSize: number;
acceleration: number;
maxSpeed: number;
loadingSpeed: number;
cost: number;
export interface ShipConfig extends ShipType {
planetRoute: Planet[];
buyCost: number;
desciption: string;
texture: string;
}
export class Ship {

View File

@ -0,0 +1,26 @@
export enum ShipClass {
light = 'light',
medium = 'medium',
heavy = 'heavy'
}
export interface ShipType {
name: string;
cargoSize: number;
loadingSpeed: number;
maxSpeed: number;
acceleration: number;
cost: number;
buyCost: number;
texture: string;
class: ShipClass;
desciption: string;
}
export const SHIP_DATA: Record<ShipClass, ShipType> = {
[ShipClass.light]: { name: 'Pioneer-01', cargoSize: 25, loadingSpeed: 15, maxSpeed: 350, acceleration: 300, class: ShipClass.light, buyCost: 3000, cost: 0.6, texture: 'swift-hauler', desciption: 'Ein kleines, schnelles Schiff. Es hat wenig Platz für Ladung, lädt aber schnell und ist sehr wendig.' },
[ShipClass.medium]: { name: 'Colony Carrier', cargoSize: 80, loadingSpeed: 20, maxSpeed: 250, acceleration: 90, class: ShipClass.medium, buyCost: 8000, cost: 1.6, texture: 'colony-carrier', desciption: 'Eine größere Version von der Pioneer-01. Der größere Frachtraum geht zu Lasten der Beschleunigung und Maximalgeschwindigkeit.' },
[ShipClass.heavy]: { name: 'Industrial Tanker', cargoSize: 400, loadingSpeed: 11, maxSpeed: 180, acceleration: 20, class: ShipClass.heavy, buyCost: 18000, cost: 3.8, texture: 'industrial-tanker', desciption: 'Ein großes behäbiges Schiff. Es wird durchaus schnell, beschleunigt aber sehr langsam und erreicht die Spitzengeschwindigkeit nur selten.' }
}

View File

@ -141,7 +141,6 @@ export class MapScene extends Phaser.Scene {
});
this.planets.push(planet);
this.gameService.planets.push(planet.model);
}
}

View File

@ -46,6 +46,8 @@ export class PlanetUi extends Phaser.Physics.Arcade.Sprite {
this.harbourImage.setDisplaySize(164, 256);
this.harbourImage.setVisible(false);
console.log(this.height)
// this.setScale(0.5)
// this.setInteractive(new Phaser.Geom.Circle(x, y, 200), Phaser.Geom.Circle.Contains);