「HowTo: Singleplayer Campaign Creation (SCAR)」の編集履歴(バックアップ)一覧に戻る

HowTo: Singleplayer Campaign Creation (SCAR) - (2007/02/24 (土) 17:01:54) の編集履歴(バックアップ)



HowTo: Singleplayer Campaign Creation (SCAR)



Hi,

There are a lot of modders and HowTo's about Multiplayer Maps. I'm a typically singleplayer and missed user created campaigns. Luckily I'm a programmer and so i decided to go deeper into SCAR. And now I can present a basic singleplayer test campaign for you to look into and build upon it.

First of all some interesting Links:

(I can't reach it actually to get the link to "Tips&Tricks", will edit later)
http://wiki.relicrank.com/index.php?title=CoH


All files go to directory "Company of Heroes\WW2\Data\Scenarios\SP" !



1.You will need a map (create anything you want, basic maps are included in attachment)
2.the worldbuilder creates a SCAR file named mapname_id.scar. Don't edit it! (as somewhere else told) it contains all markers, etc. and is updated evrytime you save it in Worldbuilder.
3.Create a file mapname.scar and fill it with e.g.

Code:

import("ScarUtil.scar")
import("tybor.scar")

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





function OnInit()

-- only for debugging
FOW_Enable(false)

-- set resources for the player
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
    • ? player5 = the AI player \n
    • ? 10 = the popcap override value \n
    • ? player_Axis = the main target for the AI \n
    • ? 1 = the difficulty setting \n
    • ? 6 = the AI production template table entry \n
    • ? 5 = the aggression setting, 1-5, 5 is the most aggressive \n
    • ? 2 = the unit preference, 1-5, 1 is infantry heavy, 5 is vehicle heavy\n
    • ? 3 = the counter preference, 1-5, 1 is anti-infantry, 5 is anti-vehicle\n
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_EnableComponent(player_Allies, false, COMPONENT_Attacking)



-- set up game objectives
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


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


This is just a simple setup of an SP Annihilation map(everything is included in attachment) with basic AI, controlling resources, spawning at markers, objective setup.

5. to be able to select the campaign you have to create a campaignname.camp file with e.g.:

Code:

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",
},
}

6. Start your CoH with the -dev option
7. You should be able to select the campaign.

The whole bunch of files (including my utility tybor.scar) can be found in the attached sp_test.zip. To use the files simple extract it to the mentioned SP folder.
The campaign consists of 2 Missions. First played as Axis, second played as Allies. Altough the AI is set up completely equal, in the 2nd mission it doesn't create any buildings (this is because AI has already 2 Victory points at beginning).

Please leave comments and suggestions here, so the code can be improved further.

Hint: I didn't wanted to edit UCS File and have found a function called LOC() which creates a LocString out of a normal string but with "LOC: " in front.

gr33tz Tybor


目安箱バナー