ActionsApi.unqueueFromProduction(queueType, objName, objType, quantity)方法說明與使用範例

| Chrono Divide | 5 Reads

以下是 @chronodivide/game-api 套件 ActionsApi 類別的一部分定義,其中包含 unqueueFromProduction 方法:

sellObject(objectId: number): void;
/** @deprecated use {@link ActionsApi.sellObject} instead */
sellBuilding(buildingId: number): void;
toggleRepairWrench(buildingId: number): void;
toggleAlliance(toPlayer: string, enabled: boolean): void;
pauseProduction(queueType: QueueType): void;
resumeProduction(queueType: QueueType): void;
queueForProduction(queueType: QueueType, objName: string, objType: ObjectType, quantity: number): void;
unqueueFromProduction(queueType: QueueType, objName: string, objType: ObjectType, quantity: number): void;

生產佇列相關的型別定義如下:

export declare enum QueueStatus {
    Idle = 0,
    Active = 1,
    /** Production is paused */
    OnHold = 2,
    /** First item is ready and is waiting to be removed before starting the next */
    Ready = 3
}

export declare enum QueueType {
    Structures = 0,
    Armory = 1,
    Infantry = 2,
    Vehicles = 3,
    Aircrafts = 4,
    Ships = 5
}

export declare enum ObjectType {
    None = 0,
    Aircraft = 1,
    Building = 2,
    Infantry = 3,
    Overlay = 4,
    Smudge = 5,
    Terrain = 6,
    Vehicle = 7,
    Animation = 8,
    Projectile = 9,
    VoxelAnim = 10,
    Debris = 11
}

AI 會在建造優先順序改變時把現有生產項目取消。以下片段節錄自 src/bot/logic/building/queueController.ts

let currentItemPriority = this.getPriorityForBuildingOption(
    currentProduction,
    game,
    playerData,
    threatCache,
);
let newItemPriority = decision.priority;
if (newItemPriority > currentItemPriority * 2) {
    logger(
        `Dequeueing queue ${queueTypeToName(queueData.type)} unit ${currentProduction.name} because ${
            decision.unit.name
        } has 2x higher priority.`,
    );
    actionsApi.unqueueFromProduction(queueData.type, currentProduction.name, currentProduction.type, 1);
}

unqueueFromProduction 的作用

此方法會從指定的生產佇列中移除某項物件(或多個相同物件):

  • queueType:指定要操作的生產線(步兵、載具、建築等)。

  • objName:規則檔中定義的物件名稱。

  • objType:物件類型,對應 ObjectType 列舉。

  • quantity:要從佇列中移除的數量。

queueController.ts 中,當 AI 判定其他單位具有顯著更高的優先度時,會執行 unqueueFromProduction 取消正在生產的項目,轉而排入新的目標。


使用示例

以下示例顯示在自定義腳本中如何手動取消佇列中的物件。假設我們想取消步兵佇列中已經排入的 GI(物件名稱 "E1"),一次取消兩個:

import { ActionsApi, QueueType, ObjectType } from "@chronodivide/game-api";

function cancelInfantry(actions: ActionsApi) {
    actions.unqueueFromProduction(
        QueueType.Infantry,  // 步兵生產線
        "E1",                 // GI 的名稱
        ObjectType.Infantry,  // 物件類型
        2                     // 取消 2 個
    );
}

呼叫後,若佇列中存在足夠數量的該物件,遊戲會依序將其從隊列中移除。不會回收資金,但也不再進行生產。若生產線因取消而變為空閒,狀態會變成 QueueStatus.Idle


總結

unqueueFromProduction 是生產管理的反向操作,可在策略調整或資源不足等情況下移除已排定的物件;搭配 queueForProductionpauseProductionresumeProduction 等方法,可靈活控制 AI 的生產佇列與節奏。

 

→返回《@chronodivide/game-api 使用教學與完整 API 對照表》

This article was last edited at