junk/entemu/common/plan.ts

366 lines
8 KiB
TypeScript
Raw Permalink Normal View History

2024-12-17 15:33:24 +00:00
import { datefrom } from "./date.ts";
export interface Plan {
name: string;
times: number;
price: number;
start: number;
amount: number;
period: number;
nextonce: boolean;
role: string;
next: Partial<Plan>[];
}
export const dplan: Plan = {
name: "新策划",
times: 1,
price: 0,
start: 0,
amount: 1,
period: 0,
nextonce: false,
role: "",
next: [],
};
export interface IPlan {
date: number;
plan: Plan;
order: number;
cost: number;
current: number;
}
export function bplan(...plan: Partial<Plan>[]): Plan {
const p = { ...dplan };
for (const p1 of plan) {
Object.assign(p, p1);
}
return p;
}
export function addplan(cal: Record<number, IPlan[]>, p: Plan): number[] {
const e: number[] = [];
let d = p.start;
for (let i = 0; i < p.times; i++) {
if (cal[d] === undefined)
cal[d] = [];
cal[d].push({
date: d,
plan: p,
order: i,
cost: p.price * p.amount,
current: 0,
});
if (!p.nextonce || (p.nextonce && i === 0))
for (const n of p.next) {
e.push(...addplan(cal, bplan(n, {
start: d + (n.start || 0),
amount: (p.amount || 1) * (n.amount || 1),
})));
}
e.push(d);
d += p.period;
}
return e;
}
export function expandplan(d: number, p: Plan): Plan[] {
const l: Plan[] = [];
for (let i = 0; i < p.times; ++i) {
l.push({ ...p, times: 1, start: d + p.period * i });
}
return l;
}
export const plandbpre: Record<string, Partial<Plan>> = {
r1_order: {
name: "采购 R1",
start: -30,
period: 30,
next: [{
name: "收取 R1",
price: 12,
start: 30,
period: 0,
role: "r1",
}],
},
r2_order: {
name: "采购 R2",
start: -30,
period: 30,
next: [{
name: "收取 R2",
price: 12,
start: 30,
period: 0,
role: "r2",
}],
},
r3_order: {
name: "采购 R3",
start: -60,
period: 60,
next: [{
name: "收取 R3",
price: 12,
start: 60,
period: 0,
role: "r3",
}],
},
r4_order: {
name: "采购 R4",
start: -60,
period: 60,
next: [{
name: "收取 R4",
price: 12,
start: 60,
period: 0,
role: "r4",
}],
},
};
export const storage_keys: Record<string, string> = {
// factory: "工厂",
// linea: "自动线",
// optimizea: "自动线技改",
p1: "P1",
p2: "P2",
p3: "P3",
p4: "P4",
p5: "P5",
r1: "R1",
r2: "R2",
r3: "R3",
r4: "R4",
r5: "R5",
};
export const plandb: Record<string, Partial<Plan>> = {
ads: {
name: "广告费",
price: 80,
},
loan: {
name: "贷款",
price: 0,
start: 0,
role: "loan",
},
loanback: {
name: "还贷",
price: 0,
start: 0,
role: "-loan",
},
strategy_ads: {
name: "战略广告",
price: 20,
start: datefrom(1, 12, 30),
period: 360,
times: 5,
},
iso9000: {
name: "ISO9000资质开发",
price: 10,
times: 2,
period: 360,
nextonce: true,
next: [{
name: "ISO9000资质开发完成",
price: 0,
start: datefrom(3, 1, 1),
}],
},
iso14000: {
name: "ISO14000资质开发",
price: 10,
times: 3,
period: 360,
nextonce: true,
next: [{
name: "ISO14000资质开发完成",
price: 0,
start: datefrom(4, 1, 1),
}],
},
market_domestic: {
name: "国内市场资质开发",
price: 10,
times: 2,
period: 360,
nextonce: true,
next: [{
name: "国内市场资质开发完成",
price: 0,
start: datefrom(3, 1, 1),
}],
},
market_asia: {
name: "亚洲市场资质开发",
price: 10,
times: 3,
period: 360,
nextonce: true,
next: [{
name: "亚洲市场资质开发完成",
price: 0,
start: datefrom(4, 1, 1),
}],
},
market_intl: {
name: "国际市场资质开发",
price: 10,
times: 4,
period: 360,
nextonce: true,
next: [{
name: "国际市场资质开发完成",
price: 0,
start: datefrom(5, 1, 1),
}],
},
rent_factory: {
name: "租用厂房",
price: 40,
times: 4,
period: 360,
role: "factory",
},
p1_cert: {
name: "P1 资质开发",
price: 10,
period: 30,
nextonce: true,
next: [{
name: "P1 资质拥有",
start: 30,
price: 0,
period: 0,
role: "p1cert",
}],
},
p2_cert: {
name: "P2 资质开发",
price: 10,
period: 30,
times: 2,
nextonce: true,
next: [{
name: "P2 资质拥有",
start: 60,
price: 0,
period: 0,
role: "p2cert",
}],
},
p4_cert: {
name: "P4 资质开发",
price: 10,
period: 60,
times: 4,
nextonce: true,
next: [{
name: "P4 资质拥有",
start: 4*60,
price: 0,
period: 0,
role: "p4cert",
}],
},
build_line_manual: {
name: "建设手工线",
price: 50,
period: 0,
role: "linem",
},
build_line_auto: {
name: "建设自动线",
times: 3,
price: 50,
period: 30,
role: "linea",
},
optimize_auto: {
name: "自动线技改",
times: 1,
price: 20,
period: 20,
role: "optimizea",
},
p1_produce: {
name: "P1 生产",
times: 30,
price: 9,
period: 0,
role: "-r1",
next: [plandbpre.r1_order, {
name: "收取 P1",
times: 1,
start: 56,
price: 0,
period: 0,
role: "p1",
}],
},
p2_produce: {
name: "P2 生产",
times: 30,
price: 9,
period: 0,
role: "-r2,-r3",
next: [plandbpre.r2_order, plandbpre.r3_order, {
name: "收取 P2",
times: 1,
start: 56,
price: 0,
period: 0,
role: "p2",
}],
},
p4_produce: {
name: "P4 生产",
times: 30,
price: 9,
period: 0,
role: "-r2,-r3,-r4,-r4",
next: [
plandbpre.r2_order,
plandbpre.r3_order,
bplan(plandbpre.r4_order, { amount: 2 }), {
name: "收取 P4",
times: 1,
start: 56,
price: 0,
period: 0,
role: "p4",
}],
},
p2_sell: {
name: "卖出 P2",
price: 0,
role: "-p2",
next: [{
name: "收到 P2 账款",
price: -52,
start: 30,
}],
},
p4_sell: {
name: "卖出 P4",
price: 0,
amount: 1,
role: "-p4",
next: [{
name: "收到 P4 账款",
price: -91,
start: 30,
}],
},
};