mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-18 18:11:24 +01:00
feat: getUnitModifiers
This commit is contained in:
parent
364d22e6ad
commit
f4959adf7a
5 changed files with 32 additions and 30 deletions
|
|
@ -1,4 +1,4 @@
|
|||
export const getDefaultMilitaryOptions: () => IMilitaryOption[] = function () {
|
||||
export const getDefaultMilitaryOptions: () => IMilitaryUnit[] = function () {
|
||||
return [
|
||||
{icon: "⚔️", name: "infantry", rural: 0.25, urban: 0.2, crew: 1, power: 1, type: "melee", separate: 0},
|
||||
{icon: "🏹", name: "archers", rural: 0.12, urban: 0.2, crew: 1, power: 1, type: "ranged", separate: 0},
|
||||
|
|
@ -21,19 +21,18 @@ export const relationsAlertRate: {[key in TRelation]: number} = {
|
|||
Enemy: 1
|
||||
};
|
||||
|
||||
type TCulture = Exclude<TCultureType, "Generic">;
|
||||
export const stateModifier: {[key in TMilitaryType]: {[key in TCulture]: number}} = {
|
||||
melee: {Nomadic: 0.5, Highland: 1.2, Lake: 1, Naval: 0.7, Hunting: 1.2, River: 1.1},
|
||||
ranged: {Nomadic: 0.9, Highland: 1.3, Lake: 1, Naval: 0.8, Hunting: 2, River: 0.8},
|
||||
mounted: {Nomadic: 2.3, Highland: 0.6, Lake: 0.7, Naval: 0.3, Hunting: 0.7, River: 0.8},
|
||||
machinery: {Nomadic: 0.8, Highland: 1.4, Lake: 1.1, Naval: 1.4, Hunting: 0.4, River: 1.1},
|
||||
naval: {Nomadic: 0.5, Highland: 0.5, Lake: 1.2, Naval: 1.8, Hunting: 0.7, River: 1.2},
|
||||
armored: {Nomadic: 1, Highland: 0.5, Lake: 1, Naval: 1, Hunting: 0.7, River: 1.1},
|
||||
aviation: {Nomadic: 0.5, Highland: 0.5, Lake: 1.2, Naval: 1.2, Hunting: 0.6, River: 1.2},
|
||||
magical: {Nomadic: 1, Highland: 2, Lake: 1, Naval: 1, Hunting: 1, River: 1}
|
||||
export const stateModifier: {[key in TMilitaryUnitType]: {[key in TCultureType]: number}} = {
|
||||
melee: {Generic: 1, Nomadic: 0.5, Highland: 1.2, Lake: 1, Naval: 0.7, Hunting: 1.2, River: 1.1},
|
||||
ranged: {Generic: 1, Nomadic: 0.9, Highland: 1.3, Lake: 1, Naval: 0.8, Hunting: 2, River: 0.8},
|
||||
mounted: {Generic: 1, Nomadic: 2.3, Highland: 0.6, Lake: 0.7, Naval: 0.3, Hunting: 0.7, River: 0.8},
|
||||
machinery: {Generic: 1, Nomadic: 0.8, Highland: 1.4, Lake: 1.1, Naval: 1.4, Hunting: 0.4, River: 1.1},
|
||||
naval: {Generic: 1, Nomadic: 0.5, Highland: 0.5, Lake: 1.2, Naval: 1.8, Hunting: 0.7, River: 1.2},
|
||||
armored: {Generic: 1, Nomadic: 1, Highland: 0.5, Lake: 1, Naval: 1, Hunting: 0.7, River: 1.1},
|
||||
aviation: {Generic: 1, Nomadic: 0.5, Highland: 0.5, Lake: 1.2, Naval: 1.2, Hunting: 0.6, River: 1.2},
|
||||
magical: {Generic: 1, Nomadic: 1, Highland: 2, Lake: 1, Naval: 1, Hunting: 1, River: 1}
|
||||
};
|
||||
|
||||
export const cellTypeModifier: {[key: string]: {[key in TMilitaryType]: number}} = {
|
||||
export const cellTypeModifier: {[key: string]: {[key in TMilitaryUnitType]: number}} = {
|
||||
nomadic: {
|
||||
melee: 0.2,
|
||||
ranged: 0.5,
|
||||
|
|
@ -66,7 +65,7 @@ export const cellTypeModifier: {[key: string]: {[key in TMilitaryType]: number}}
|
|||
}
|
||||
};
|
||||
|
||||
export const burgTypeModifier: {[key: string]: {[key in TMilitaryType]: number}} = {
|
||||
export const burgTypeModifier: {[key: string]: {[key in TMilitaryUnitType]: number}} = {
|
||||
nomadic: {
|
||||
melee: 0.3,
|
||||
ranged: 0.8,
|
||||
|
|
|
|||
|
|
@ -7,9 +7,9 @@ export function generateMilitary(states: TStates) {
|
|||
|
||||
if (!options.military) options.military = getDefaultMilitaryOptions();
|
||||
|
||||
// const unitModifiers = getUnitModifiers(states);
|
||||
const unitModifiers = getUnitModifiers(states);
|
||||
|
||||
console.log(states);
|
||||
console.log({states, unitModifiers});
|
||||
|
||||
TIME && console.timeEnd("generateMilitaryForces");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,19 +3,22 @@ import {isState} from "utils/typeUtils";
|
|||
|
||||
// calculate overall state modifiers for unit types based on state features
|
||||
export function getUnitModifiers(states: TStates) {
|
||||
const validStates = states.filter(isState);
|
||||
return states.map(state => {
|
||||
if (!isState(state)) return {};
|
||||
|
||||
for (const state of validStates) {
|
||||
const military = {platoons: []};
|
||||
const {i: stateId, relations, expansionism, area, neighbors, alert} = state;
|
||||
const unitModifiers: Dict<number> = {};
|
||||
const {type: stateType, formName, form, alert} = state;
|
||||
|
||||
for (const unit of options.military) {
|
||||
if (!stateModifier[unit.type]) continue;
|
||||
for (const {type, name} of options.military) {
|
||||
if (!stateModifier[type]) continue;
|
||||
|
||||
let modifier = stateModifier[unit.type][s.type] || 1;
|
||||
if (unit.type === "mounted" && s.formName.includes("Horde")) modifier *= 2;
|
||||
else if (unit.type === "naval" && s.form === "Republic") modifier *= 1.2;
|
||||
military[unit.name] = modifier * alert;
|
||||
let modifier = stateModifier[type][stateType] || 1;
|
||||
if (type === "mounted" && formName.includes("Horde")) modifier *= 2;
|
||||
else if (type === "naval" && form === "Republic") modifier *= 1.2;
|
||||
|
||||
unitModifiers[name] = modifier * alert;
|
||||
}
|
||||
}
|
||||
|
||||
return unitModifiers;
|
||||
});
|
||||
}
|
||||
|
|
|
|||
2
src/types/globals.d.ts
vendored
2
src/types/globals.d.ts
vendored
|
|
@ -26,7 +26,7 @@ interface IOptions {
|
|||
winds: [number, number, number, number, number, number];
|
||||
stateLabelsMode: "auto" | "short" | "full";
|
||||
year: number;
|
||||
military: IMilitaryOption[];
|
||||
military: IMilitaryUnit[];
|
||||
}
|
||||
|
||||
declare let populationRate: number;
|
||||
|
|
|
|||
6
src/types/pack/states.d.ts
vendored
6
src/types/pack/states.d.ts
vendored
|
|
@ -53,15 +53,15 @@ type TRelation =
|
|||
| "Enemy"
|
||||
| "x";
|
||||
|
||||
interface IMilitaryOption {
|
||||
interface IMilitaryUnit {
|
||||
name: string;
|
||||
icon: string;
|
||||
crew: number;
|
||||
power: number;
|
||||
rural: number;
|
||||
urban: number;
|
||||
type: TMilitaryType;
|
||||
type: TMilitaryUnitType;
|
||||
separate: Logical;
|
||||
}
|
||||
|
||||
type TMilitaryType = "melee" | "ranged" | "mounted" | "machinery" | "naval" | "armored" | "aviation" | "magical";
|
||||
type TMilitaryUnitType = "melee" | "ranged" | "mounted" | "machinery" | "naval" | "armored" | "aviation" | "magical";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue