Improve ready task selection
This commit is contained in:
@ -18,7 +18,7 @@ export function calcHeroResource(requirements: ReadonlyArray<Resources>): HeroRe
|
||||
|
||||
function getFirstRequirement(requirements: ReadonlyArray<Resources>): Resources {
|
||||
for (let required of requirements) {
|
||||
if (required.lt(Resources.zero())) {
|
||||
if (required.anyLower(Resources.zero())) {
|
||||
return required;
|
||||
}
|
||||
}
|
||||
|
@ -85,14 +85,20 @@ export class Resources implements ResourcesInterface {
|
||||
);
|
||||
}
|
||||
|
||||
lt(other: ResourcesInterface): boolean {
|
||||
anyLower(other: ResourcesInterface): boolean {
|
||||
return this.lumber < other.lumber || this.clay < other.clay || this.iron < other.iron || this.crop < other.crop;
|
||||
}
|
||||
|
||||
gt(other: ResourcesInterface): boolean {
|
||||
allGreater(other: ResourcesInterface): boolean {
|
||||
return this.lumber > other.lumber && this.clay > other.clay && this.iron > other.iron && this.crop > other.crop;
|
||||
}
|
||||
|
||||
allGreaterOrEqual(other: ResourcesInterface): boolean {
|
||||
return (
|
||||
this.lumber >= other.lumber && this.clay >= other.clay && this.iron >= other.iron && this.crop >= other.crop
|
||||
);
|
||||
}
|
||||
|
||||
min(other: ResourcesInterface): Resources {
|
||||
return new Resources(
|
||||
Math.min(this.lumber, other.lumber),
|
||||
|
@ -83,7 +83,11 @@ export class VillageTaskCollection {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return _.first(firstReadyGroup.tasks);
|
||||
const maxCapacity = Resources.fromStorage(this.storage.getResourceStorage());
|
||||
|
||||
return firstReadyGroup.tasks.find(
|
||||
t => !t.args.resources || maxCapacity.allGreaterOrEqual(Resources.fromObject(t.args.resources))
|
||||
);
|
||||
}
|
||||
|
||||
postponeTask(taskId: TaskId, seconds: number) {
|
||||
|
Reference in New Issue
Block a user