德国陆军中校 ★★★
- UID
- 766547
- 主题
- 0
- 阅读权限
- 100
- 帖子
- 5628
- 精华
- 9
- 积分
- 6605
- 金钱
- 14321
- 荣誉
- 199
- 人气
- 2
- 在线时间
- 0 小时
- 评议
- 0
- 帖子
- 5628
- 精华
- 9
- 积分
- 6605
- 金钱
- 14321
- 荣誉
- 199
- 人气
- 2
- 评议
- 0
|
让你的对战地图动起来,创建自己的战役地图,添加行代码和AI 事件
有很多朋友提到了想要制作战役地图,本文旨在抛砖引玉,帮助大家理解英雄连地图文件中的代码和事件,期望强人能做出我们自己的战役地图,以飨读者。
文中代码如果需要拷贝时,最好删除其中的中文解释部分,因为如果是在eclipse(注:java开发软件 开源)下运行的话,注释的格式并不统一,为防止错误,最好删除注释 正确的格式应该是 <!--------- 注释内容 ------->
所有的工作在"Company of Heroes\WW2\Data\Scenarios\SP" 下进行,要注意是"SP"不是"MP"
1,第一步,你需要一张地图,你可以选择一张地图或者创建新的地图。
2,使用Worldbuilder创建一个SCAR文件,取名为: 地图名_id_scar,很重要。
3.创建一个新scar文件,取名为地图名.scar,然后在里面加入代码,很重要。
import("ScarUtil.scar")
import("tybor.scar")
--学过java的都知道,导入类和封包
function OnGameSetup()
--设置双方势力
player_Axis = Setup_Player(1, 95050, "Axis", 1)
player_Allies = Setup_Player(2, 95000, "Allies", 2)
end
function OnGameRestore()
--------------------使用自带类里的方法初始化变量
player_Axis = World_GetPlayerAt(1)
player_Allies = World_GetPlayerAt(2)
-- function takes care of restoring all global mission parameters after a save/load
Game_DefaultGameRestore()
end
-------------------------------------------------------------------------
-- [[ ONINIT ]]
-------------------------------------------------------------------------
function OnInit()
-- only for debugging
FOW_Enable(false)
--调用上面的方法设定势力 实例化变量
-- set resources for the player 设置资源Manpower人力Munition弹药Fuel油料
Tybor_PlayerResourceAdd(player_Axis, RT_Manpower, -70)
Tybor_PlayerResourceAdd(player_Axis, RT_Munition, 10)
Tybor_PlayerResourceAdd(player_Axis, RT_Fuel, 20)
Player_SetResource(player_Axis, RT_Manpower, 600)
Player_SetResource(player_Axis, RT_Munition, 600)
Player_SetResource(player_Axis, RT_Fuel, 200)
Tybor_PlayerResourceAdd(player_Allies, RT_Manpower, -70)
Tybor_PlayerResourceAdd(player_Allies, RT_Munition, 10)
Tybor_PlayerResourceAdd(player_Allies, RT_Fuel, 20)
Player_SetResource(player_Allies, RT_Manpower, 600)
Player_SetResource(player_Allies, RT_Munition, 600)
Player_SetResource(player_Allies, RT_Fuel, 200)
-- Modify_PlayerResourceRate(player_Axis, RT_Manpower, 0)
-- Modify_PlayerResourceRate(player_Axis, RT_Munition, 0)
-- Modify_PlayerResourceRate(player_Axis, RT_Fuel, 0)
-- Modify_PlayerResourceRate(player_Allies, RT_Manpower, 0)
-- Modify_PlayerResourceRate(player_Allies, RT_Munition, 0)
-- Modify_PlayerResourceRate(player_Allies, RT_Fuel, 0)
--Player_SetAbilityAvailability(player_Axis, ABILITY.AXIS_THROWGRENADE, ITEM_UNLOCKED)
--Player_SetAbilityAvailability(player_Allies, ABILITY.ALLIED_THROWGRENADE, ITEM_UNLOCKED)
Player_SetUpgradeAvailability(player_Axis, UPG.AXIS_FLAMETHROWER, ITEM_LOCKED)
Player_SetUpgradeAvailability(player_Allies, UPG.ALLIED_FLAMETHROWER, ITEM_LOCKED)
-- get the difficulty
--g_dif = Game_GetSPDifficulty()
-- set health bonus for player (Allies get bonus! see Setup_Difficulty)
--Setup_Difficulty(player_Allies, g_dif)
-- set health handicap for player (Axis get handicap ! see Setup_Difficulty)
--Setup_Difficulty(player_Axis, g_dif)
-- Spawn Squads
sg_allied_engineers = SGroup_CreateIfNotFound("sg_allied_engineers")
Util_CreateSquadsAtMarker(player_Allies, sg_allied_engineers, SBP.ALLIED_ENGINEER, mkr_Allies_Spawn, 1)
sg_axis_pioneer = SGroup_CreateIfNotFound("sg_axis_pioneer")
Util_CreateSquadsAtMarker(player_Axis, sg_axis_pioneer, SBP.AXIS_PIONEER, mkr_Axis_Spawn, 1)
---------------------
-- Sample AI setup --
---------------------
--? An example use:\n
--? Util_AI_Setup(player5, 10, player_Axis, 1, 6, 5, 2, 3)\n AI设定的例子
--? player5 = the AI player \n 电脑玩家
--? 10 = the popcap override value \n
--? player_Axis = the main target for the AI \n 电脑AI的胜利目标设定
--? 1 = the difficulty setting \n 游戏难度设定
--? 6 = the AI production template table entry \n AI
--? 5 = the aggression setting, 1-5, 5 is the most aggressive \n AI侵略性 5最高 1最低
--? 2 = the unit preference, 1-5, 1 is infantry heavy, 5 is vehicle heavy\n AI生产的侧重点1-5 1是步兵 数字往上是装甲部队
--? 3 = the counter preference, 1-5, 1 is anti-infantry, 5 is anti-vehicle\n AI计算的侧重点1-5 1是反步兵数字往上是反装甲部队
--下面是个设定例子
Tybor_AI_Setup(player_Allies, {Util_DifVar({10, 15, 20, 30}), 5}, Game_GetSPDifficulty(), 1, Util_DifVar({1, 2, 3,
5}), 2, 3)
-- tell AI to go after strongest threat instead of the weakest
AI_DoString( player_Allies, "s_personality.attack_prefer_threat = true" )
AI_DoString( player_Allies, "s_personality.defend_prefer_threat = true" )
-- tell AI not to "defend" territories outside of the ring around its base
AI_EnableComponent(player_Allies, false, COMPONENT_ForwardDefending)
-- enable use of comapny commander menu and abilities 允许或禁止使用科技树技能
AI_DoString( player_Allies, "s_commandtree_enabled = true" )
AI_DoString( player_Allies, "s_playerabilities_enabled = true" )
-- tell AI to not attack target 告诉AI 不要攻击某个目标
AI_EnableComponent(player_Allies, false, COMPONENT_Attacking)
-- 设置游戏目标
Initialize_OBJ_Annihilate()
Objective_Start(OBJ_Annihilate, true)
-- Start up the main game logic loop
Rule_Add(SP_test_MainLoop)
end
Scar_AddInit(OnInit)
--------------------------------------------------------------------------------------------
-- MISSION SCRIPTS 一个任务脚本 java 和javascript写的 参考下面和上面的片代码可以自己学习
-------------------------------------------------------------------------------------------------
function SP_test_MainLoop()
-- executed every frame
end
function Initialize_OBJ_Annihilate()
OBJ_Annihilate = {
SetupUI = function() end,
OnStart = function()
-- win condition
Rule_AddInterval(OBJ_Annihilate_WinCondition, 5)
end,
OnComplete = function()
-- we won
Game_EndSP( true, nil, true )
end,
OnFail = function()
-- we failed
Game_EndSP( false, nil, true )
end,
Title = LOC("Annihilate all enemy forces!"),
Description = LOC("There is a small base of Allied forces which has to be destroyed."),
Type = OT_Primary,
Icon = IT_P_Attack,
}
Objective_Register(OBJ_Annihilate)
end
function OBJ_Annihilate_WinCondition()
-- Player_GetAll creates sg_allsquads per default (see description)
Player_GetAll(player_Axis)
if SGroup_IsEmpty(sg_allsquads) then
-- you loose
Objective_Fail(OBJ_Annihilate)
Rule_RemoveMe()
end
Player_GetAll(player_Allies)
if SGroup_IsEmpty(sg_allsquads) then
-- you win
Objective_Complete(OBJ_Annihilate)
Rule_RemoveMe()
end
end
这里面是地图的AI 设置,包括基本AI,资源控制AI,建造AI等。
Name="Single Player Test Campaign"
ModName="WW2"
Missions = {
{
name = "Single Player Test Mission - Axis",
mission = "sp_axis_test",
},
{
name = "Single Player Test Mission - Allies",
mission = "sp_allies_test",
},
}
附加一些代码
function OnGameSetup()
-- 在敌人建筑物被彻底摧毁后是否强制结束游戏 boolean型 学软件的应该知道
g_CheckAnnihilate = false
-- 限定玩家的属性
player1 = World_GetPlayerAt(1)
player2 = World_GetPlayerAt(2)
-- executes code that cant be run here inside OnGameSetup()
Rule_AddOneShot(init1, 0)
-- 检测游戏是否结束的频率 设为1表示时刻在检测
Rule_AddInterval(victorycheck, 1)
-- 每10秒呼叫1次炮兵轰炸的参考码
Rule_AddInterval(arty_ammo, 10)
-- 每20秒呼叫一队步兵连增援的参考码
Rule_AddInterval(squadspawner, 20)
end
function init1()
-- 播放音乐的代码 括号里是路径
Util_PlayMusic("SOUND/Music/enterthesqarecombat", 0, 0)
-- 允许或者禁止科技树 false为禁止 true 允许 不能改成别的
UI_BindingSetEnabled( "company_commander", false)
-- 给于玩家一个技能的代码 第一行ally_air_strike_ability_strafe是轰炸机轰炸 第二行_v1_weapon是V1导弹 具体文件自己找了替换
Player_SetAbilityAvailability(player1, Util_GetAbilityID("abilities/ally_air_strike_ability_strafe.lua"), ITEM_UNLOCKED)
Player_SetAbilityAvailability(player2, Util_GetAbilityID("abilities/axis_v1_weapon.lua"), ITEM_UNLOCKED)
-- 设置玩家200的人口限制
Player_SetPopCapOverride(player1, 200, -1, -1)
Player_SetPopCapOverride(player2, 200, -1, -1)
Player_AddResource(player1, RT_Munition, 1000)
Player_AddResource(player2, RT_Munition, 1000)
-- 设置盟军每次建造一个单位组的数量(待验证)这里设成了1 一队兵里就一个人。。
ALLIED_OFFICER1 = Util_GetSquadBlueprintID("sbps/races/allies/soldiers/captain.lua")
sg_ally_o1 = SGroup_CreateIfNotFound("sg_ally_o1")
Util_CreateSquadsAtMarker(player1, sg_ally_o1, ALLIED_OFFICER1, marker1, 1)
-- 同上 不过是德军
AXIS_OFFICER1 = Util_GetSquadBlueprintID("sbps/races/axis/soldiers/officer_squad.lua")
sg_axis_o1 = SGroup_CreateIfNotFound("sg_axis_o1")
Util_CreateSquadsAtMarker(player2, sg_axis_o1, AXIS_OFFICER1, marker2, 1)
end
function squadspawner()
-- 事件:战场增援 并让他们前往指定地方 前两行分别是步兵连和吉普车的行代码,第三行是创建增援,下面两行是触发事件(分盟军和德军 )
ALLIED_RIFLEMAN = Util_GetSquadBlueprintID("sbps/races/allies/soldiers/rifleman_squad.lua")
ALLIED_JEEP = Util_GetSquadBlueprintID("sbps/races/allies/vehicles/jeep_squad.lua")
sg_ally_assault = SGroup_CreateIfNotFound("sg_ally_assault")
Util_CreateSquadsAtMarker(player1, sg_ally_assault, ALLIED_RIFLEMAN, marker1, 1)
Util_CreateSquadsAtMarker(player1, sg_ally_assault, ALLIED_JEEP, marker1, 2)
Cmd_MoveToMarker(sg_ally_assault, marker2)
AXIS_VOLKS = Util_GetSquadBlueprintID("sbps/races/axis/soldiers/volksgrenadier_squad.lua")
AXIS_BIKE = Util_GetSquadBlueprintID("sbps/races/axis/vehicles/motorcycle_squad.lua")
sg_axis_assault = SGroup_CreateIfNotFound("sg_axis_assault")
Util_CreateSquadsAtMarker(player2, sg_axis_assault, AXIS_VOLKS, marker2, 1)
Util_CreateSquadsAtMarker(player2, sg_axis_assault, AXIS_BIKE, marker2, 2)
Cmd_MoveToMarker(sg_axis_assault, marker1)
end
function victorycheck()
-- 检查某一方势力兵力不存在时 是否结束游戏 (分盟军和德军)
if SGroup_GetAvgHealth(sg_ally_o1) == 0 then
EventCue_Create(CUE_NORMAL, 900000, 900000)
loser = player1;
Rule_AddOneShot(gameover, 8)
Rule_RemoveMe()
end
if SGroup_GetAvgHealth(sg_axis_o1) == 0 then
EventCue_Create(CUE_NORMAL, 900001, 900001)
loser = player2;
Rule_AddOneShot(gameover, 8)
Rule_RemoveMe()
end
end
function gameover()
-- 游戏结束的代码
Player_Kill(loser);
end;
function arty_ammo()
-- add ammo
Player_AddResource(player1, RT_Munition, 100)
Player_AddResource(player2, RT_Munition, 100)
-- 给地图上某一点在特定的时候创造炮兵轰炸 前两行是轰炸技能代码 第三行是时间 target.x = target.x + World_GetRand(-50, 50)target.z = target.z + World_GetRand(-50, 50)表示坐标
if World_GetRand(0, 1) == 0 then
bomber = World_GetPlayerAt(World_GetRand(1, 2))
ABILITY_ALLIED_ARTILLERY = Util_GetAbilityID("abilities/off_map_artillery_ability.lua")
target = Util_GetPosition(Marker_FromName("marker"..World_GetRand(3,17), "blue_marker"))
target.x = target.x + World_GetRand(-50, 50)
target.z = target.z + World_GetRand(-50, 50)
Cmd_PlayerAbilityPos(bomber, ABILITY_ALLIED_ARTILLERY, target, true)
end
end
我的空间 这里有个编辑过的地图文件,供感兴趣的朋友学习之用。
[ 本帖最后由 njxxf1983 于 2007-5-18 11:31 编辑 ] |
-
总评分: 金钱 + 20
查看全部评分
|