Introduction
资源管理模块的 Introduction
/**
* 资源模块的资源定义
* 除了常规的资源外, 还包含 容量 这种资源
*
* 但是, 部分建筑的不同资源的容量是不共通的.
* 其中有:
* - Lab: energy 和 mineral
* - Nuker: energy 和 ghodium
* - PowerSpawn: energy 和 power
*
* 所以, 对于容量的描述需要复杂一些. 这里总共归为三类:
* - capacity: 正常的容量, 适用于一般的建筑
* - capacity_energy: 能量的容量
* - capacity_mineral: mineral / ghodium / power 的容量
*
* 但是, 实际上, 对于 Lab 我们应该对不同的矿物考虑不同的容量.
* 因为, 假如 Lab 中放了矿物 A, 矿物 B就不能放进去了. 但是,
* 这种多重容量的实现过于复杂, 代价很大. 所以我们使用矿物来统一
* 代替, 表示放当前矿物的情况下能放多少. 这种矿物不共通的问题由
* 调用段来承担, 例如可以写出这样的代码:
* if (lab.mineralType !== yourMineral) return OK_STOP_CURRENT
* 而对于只能存放特定资源的建筑来说, 例如 Spawn, 约定是选择最准确的描述
*/
type ResourceType = ResourceConstant | "capacity" | "capacity_energy" | "capacity_mineral"
/**
* 数量描述器
* 包含了 精准数量, 有上界 (<=), 有下界 (>=) 和 有上下界 (>=, <=)
*/
type AmountDescriptor = number | { upperBound: number } | { lowerBound: number } | { lowerBound: number, upperBound: number }
/** 解析数量描述器到统一的有上下界描述 */
function parseAmountDescriptor(amountDescriptor: AmountDescriptor): { lowerBound: number, upperBound: number } {
if ( typeof amountDescriptor === "number" )
return { lowerBound: amountDescriptor, upperBound: amountDescriptor }
else if ( !("lowerBound" in amountDescriptor) )
// 下界默认是 1
return { lowerBound: 1, upperBound: amountDescriptor["upperBound"] }
else if ( !("upperBound" in amountDescriptor) )
// 上界默认是 无穷
return { lowerBound: amountDescriptor["lowerBound"], upperBound: Infinity }
else
return amountDescriptor
}
/** 可存取的建筑, 并不包含 Ruin 和 TombStone */
interface StorableStructure extends OwnedStructure {
/**
* A Store object that contains cargo of this structure.
*/
store: StoreDefinition |
Store<RESOURCE_ENERGY, false> | // Spawn, Extension
Store<RESOURCE_ENERGY | RESOURCE_POWER, false> | // PowerSpawn
Store<RESOURCE_ENERGY | MineralConstant | MineralCompoundConstant, false> | // Lab
Store<RESOURCE_ENERGY | RESOURCE_GHODIUM, false> // Nuker
}🧱 建筑资源管理
📃 资源管理模块的具体实现
Last updated