MapApi.getTheaterType()
Copyright Notice: This article is an original work licensed under the CC 4.0 BY-NC-ND license.
If you wish to repost this article, please include the original source link and this copyright notice.
Source link: https://v2know.com/article/1225
MapApi.getTheaterType()
回傳目前地圖的劇院類型(TheaterType
)。
型別宣告及相關方法位於 @chronodivide/game-api
的 index.d.ts
檔案中:
684 getRealMapSize(): Size;
685 /** Tile coordinates for each player starting position */
686 getStartingLocations(): Vector2[];
687 getTheaterType(): TheaterType;
688 getTile(rx: number, ry: number): Tile | undefined;
TheaterType
的列舉值如下,對應不同的地圖風格:
export declare enum TheaterType {
None = 0,
Temperate = 1,
Urban = 2,
Snow = 4,
Lunar = 8,
Desert = 16,
NewUrban = 32,
All = 63
}
壓縮後的實作僅將呼叫轉交給內部資料來源:
getTheaterType(){return Op(this,Cp,"f").getTheaterType()}
如何運用
此方法常用來判斷地圖的主題(如雪地、都市、月球等),以便在初始化或搜尋單位美術資料時載入對應的資源。
以下是一個簡易 bot 範例,於遊戲開始時印出地圖劇院類型:
import { cdapi, Bot, GameApi, TheaterType } from "@chronodivide/game-api";
class TheaterLoggerBot extends Bot {
onGameStart(game: GameApi) {
const theater = game.mapApi.getTheaterType();
switch (theater) {
case TheaterType.Temperate:
console.log("This map uses the Temperate theater.");
break;
case TheaterType.Snow:
console.log("Snow theater detected – prepare for icy terrain!");
break;
default:
console.log("Theater type:", TheaterType[theater]);
}
}
}
async function main() {
await cdapi.init(process.env.MIX_DIR!);
await cdapi.createGame({
agents: [new TheaterLoggerBot("Scout", "Americans")],
mapName: "mp03t4.map",
shortGame: true,
online: false,
});
}
main().catch(console.error);
在 onGameStart
中呼叫 game.mapApi.getTheaterType()
,即可取得列舉值 TheaterType
,進而判定目前地圖的環境風格,讓 AI 能根據劇院類型調整策略或載入特定資源。
此方法通常與其他 MapApi
功能配合使用,用以了解地圖整體特性。
→返回《@chronodivide/game-api 使用教學與完整 API 對照表》
This article was last edited at