StartLocationを自由に設定する

 Starcraft2でMapを作る場合、Start Locationの設定は結構問題が多い。COOPで人間側を特定の場所に、AIを別の場所に固めることは、普通のmapでは設定できない。Triggerを使用しようにも、Start Locationsは、参照できても設定はできないようになっている。

 解決方法だが、まず『Create melee starting units for all players』と、『Start the melee AI for all computer players』の代替えactionが必要になる。

 前者は比較的簡単に設定できるが、後者はいろいろ試してみた結果、main townを設定してやれば、AIがうまく動作することがわかった。今のところ問題は出ていない。

How to change Start Locations by Triggers Module.

 準備として標準のMelee Initializationから、『Create melee starting units for all players』と『Start the melee AI for all computer players』をClearして、代替えactionを設定する。

 また、StartLocationsというpoint形式の配列変数を作っておく。人数分(max 15なので15でもいい)の配列を作っておく。これに予め、Terrain Moduleで作ったStart Locationを割り当てておく。乱数を使えば、ランダム割り当てもできるが、この部分は割愛する。

    • StartLocations = No Point

 action内にPick Each Player In Player Groupを追加して、Team内のそれぞれのplayer(action内ではpicked playerとして参照される)に設定をする。

  • ※もちろん、Team毎にStart Locationを設定する場合の方法で、個々のplayerに設定する場合は、下記のscriptのpicked playerの部分を個々に指定する。
Replace "Create melee starting units for all players" with this script.

 以下のスクリプトを設置する。内容は、picked playerのRace(種族)に合わせて、picked playerの初期ユニットを、StartLocation変数に収められたpointに設置する。

    • Melee - Create (Race of player (Picked player)) melee starting units for player (Picked player) at StartLocations[(Picked player)]
Replace "Start the melee AI for all computer players" with these script.

 以下のスクリプトを設置する。内容は、picked playerのAIを初期設定し、新しいtownをStartLocationに設置。その新しいtownをmain townとして設定。最後に、初期のworkerに採取を指示する。

    • AI Advanced - Initialize the AI for player (Picked player)
    • AI Advanced - Create a new town for player (Picked player) at point StartLocations[(Picked player)]
    • AI Advanced - Set town (Get the town owned by player (Picked player) closest to point StartLocations[(Picked player)]) to be the main town for player (Picked player)
    • AI Advanced - Start a new harvest job at town (Get the town owned by player (Picked player) closest to point StartLocations[(Picked player)]) for player (Picked player).
  • ※まず、これらはComputerのplayerに対してのみ設定する。条件文で、Controller of playerがComputerかどうか調べれば良い。
  • ※一行目が無いとtown設定ができない。townはAIのための設定なので、AIが設定されてないと当然設定できないようだ。
  • ※三行目でmain townを設定しないと、AIは自動で割り振られた本来のStart Locationを中心に建築・防衛を始めてしまう。
  • ※三行目。townは整数が割り振られてその数値で識別・管理するのだが、数値の指定が面倒そうなので、単純にStartLocationに収められた位置からいちばん近いtownを呼び出している。
  • ※四行目が無いと、初期のworkerが動かない。

 とりあえずはこれでAIは動作する。テストしてみたが、問題は無さそう。

 特定のplayerを特定のStart Locationに割り当てたい場合、playerの色で判別する方法が簡単。Player Colorで、プリセットの色リストを指定して判断してやるだけ。

追記

 AIがExpandを本来のStart Locationの近くに作る問題と、AIがExpandしなくなる問題を修正しました。

Change Start Locations by Triggers Module. [example]

 内容は、teamの初期位置を001〜004側と005〜008側に分けて指定するというもの。それぞれのteam内での位置はランダムになる。
 Initialize locationsの部分でTeam数とTeamの人数とそれぞれのStart Location Pointを必要なだけ設定してやる。

 また、AIがExpandを本来のStart Locationの近くに作る問題があるので、Player PropertiesでStart Locationをrandomではなく、指定したい位置に固定する。さらに、Team内にAI Playerが一人でも含まれていた場合、Start Locationはランダムではなく固定になるよう修正してある。

Melee Initialization
Events
Game - Map initialization
Local Variables
TeamAICheck = false
StartLocations = No Point
StartLoc = No Point
StartLocPoint = No Point
CheckStartLoc = false
I = 0
J = 0
TeamMemNumber = 4
TeamNumber = 2
team_num = 0
Conditions
Actions
------- Initialize locations
Variable - Set TeamNumber = 2
Variable - Set TeamMemNumber[1] = 4
Variable - Set TeamMemNumber[2] = 4
Variable - Set StartLocPoint[1][1] = Start Location 001
Variable - Set StartLocPoint[1][2] = Start Location 002
Variable - Set StartLocPoint[1][3] = Start Location 003
Variable - Set StartLocPoint[1][4] = Start Location 004
Variable - Set StartLocPoint[2][1] = Start Location 005
Variable - Set StartLocPoint[2][2] = Start Location 006
Variable - Set StartLocPoint[2][3] = Start Location 007
Variable - Set StartLocPoint[2][4] = Start Location 008
------- Set Random locations
Variable - Set team_num = 1
General - While (Conditions) are true, do (Actions)
Conditions
team_num <= TeamNumber
Actions
Variable - Set I = 1
General - While (Conditions) are true, do (Actions)
Conditions
I <= TeamMemNumber[team_num]
Actions
Variable - Set J = (Random integer between 1 and TeamMemNumber[team_num])
General - If (Conditions) then do (Actions) else do (Actions)
If
CheckStartLoc[team_num][J] == false
Then
Variable - Set StartLoc[team_num][I] = StartLocPoint[team_num][J]
Variable - Set CheckStartLoc[team_num][J] = true
Variable - Set I = (I + 1)
Else
Variable - Set team_num = (team_num + 1)
------- Check AI Controll
Variable - Set team_num = 1
General - Repeat (Actions) TeamNumber times
Actions
Variable - Set J = 1
Player Group - Pick each player in (Players on team team_num) and do (Actions)
Actions
General - If (Conditions) then do (Actions) else do (Actions)
If
(Controller of player (Picked player)) == Computer
Then
Variable - Set TeamAICheck[team_num] = true
Else
Variable - Set J = (J + 1)
Variable - Set team_num = (team_num + 1)
------- Set AI locations for AI Expand Issue
Variable - Set team_num = 1
General - While (Conditions) are true, do (Actions)
Conditions
team_num <= TeamNumber
Actions
General - If (Conditions) then do (Actions) else do (Actions)
If
TeamAICheck[team_num] == true
Then
Variable - Set I = 1
General - While (Conditions) are true, do (Actions)
Conditions
I <= TeamMemNumber[team_num]
Actions
Variable - Set StartLoc[team_num][I] = StartLocPoint[team_num][I]
Variable - Set I = (I + 1)
Else
Variable - Set team_num = (team_num + 1)
------- Set Initial Unit for all players
Variable - Set team_num = 1
General - Repeat (Actions) TeamNumber times
Actions
Variable - Set J = 1
Player Group - Pick each player in (Players on team team_num) and do (Actions)
Actions
Variable - Set StartLocations[(Picked player)] = StartLoc[team_num][J]
Melee - Create (Race of player (Picked player)) melee starting units for player (Picked player) at StartLocations[(Picked player)]
General - If (Conditions) then do (Actions) else do (Actions)
If
(Controller of player (Picked player)) == Computer
Then
AI Advanced - Initialize the AI for player (Picked player)
General - If (Conditions) then do (Actions) else do (Actions)
If
StartLocations[(Picked player)] != (Start location of player (Picked player))
Then
AI Advanced - Create a new town for player (Picked player) at point StartLocations[(Picked player)]
AI Advanced - Set town (Get the town owned by player (Picked player) closest to point StartLocations[(Picked player)]) to be the main town for player (Picked player)
AI Advanced - Start a new harvest job at town (Get the town owned by player (Picked player) closest to point StartLocations[(Picked player)]) for player (Picked player).
Else
Else
Variable - Set J = (J + 1)
Variable - Set team_num = (team_num + 1)
Melee - Set melee starting resources for all players
Melee - Set default melee options for all players