AI Scripting and Orders

One new feature of 2.0.6 was the ability to set up a list of up to 4 orders for the AI to follow. This is now the recommended way to order the AI's unit around.

The Order List

Team orders include a destination (either an AI point or a tile coordinate), and an aggression to use for the order. There are some helper functions included in FUNCTIONS.BSF (MakeAIOrderCoord and MakeAIOrderAIPoint) and so giving orders is as simple as the examples below:

// Give team 0 on side 1 (the AI side) a sequence of 3 orders

// first order, go to 30, 26 with aggression 2 (move as a group)
SetTeamOrder(1, 0, 0, MakeAIOrderCoord(30, 26, 2)) ;

// then, once you get there, head to AI point 4 with aggression 8 (avoid enemy while moving)
SetTeamOrder(1, 0, 1, MakeAIOrderAIPoint( 4, 8)) ;

// once there, change to aggression 16 (seek and destroy).  0,0 coordinate means we don't want to set a team destination.
SetTeamOrder(1, 0, 2, MakeAIOrderCoord(0,0, 16)) ;

As orders are executed they will be removed from the list, and the remaining orders will move up. So you can use GetTeamOrder to determine which orders have been completed and which have not.

Immediate Ordering

Orders will wait for the previous order to complete (that is, the for team to not have a destination it is trying to get to) before the next order begins. If you want to have direct control over your team (e.g. to react to the player) then you can directly set team data 0 using the SetTeamData function and the MakeAI* functions above. An alternative is to use the MoveTeam helper function, as shown below.

// move team 3 to AI point 6, with aggression 8
MoveTeam(1, 3, 6, 8) ;

// move team 4 to 22,32 using aggression 2.  Note that you need to pass the aggression in twice
// once to the helper function and once to MoveTeam
MoveTeam(1, 4, MakeAIOrderCoord(22, 32, 2), 2) ;

Update 2.0.6 New Features

Share Unofficial User Scenarios on Any Platform

You can now both test your own campaigns on any platform, and also share them with your friends and the community.

To do this you will first need somewhere online to host your data. You can use any webspace, or many sharing and backup applications (like Dropbox as an example) allow you to get URLs which link to your files. Basically, if it is a URL you can use on the web, then you can use it to host your files.

There are then a number of steps you need to go through. First, any campaigns need to be packaged into a single .CPF file. This is done by first enabling debug mode (add the DEBUGMODE 1 line to your USER.TXT file), and then you will see a new Slitherine button when you choose Editor from the main menu. Simply select the campaign you wish to package and hit the button. The cursor will stop responding until the campaign has been packaged up. You can then find the CPF file in the same folder as the campaign.

You also need a .LST file containing details of your campaign, such as a short description and some other details. The format of this file is as follows

FILENAME <the name of this file>

[0]
NAME <CPF filename>
SHOWNAME <campaign name>
DESC <short description of the campaign>
MAKER <your username>
TYPE <0 for single player, 1 for multiplayer>
SIZE <in MB>
#URL <the full URL of the CPF file to download>

[1]
....

As you can see, you can have more than 1 chunk in the file, meaning you can use a single .LST file to add multiple campaigns to the download list. The FILENAME entry is optional, but if you include it then the game will cache the file and reload it each time, meaning you can permanently add the campaigns to your list. Note that redownloading a LST file with the same name will update the file, so be sure to use a unique filename for your LST file.

An example of a LST file is

FILENAME PIP_BETA.LST

[0]
NAME BETA_Slith_MP_Random.CPF
SHOWNAME BETA Slitherine MP Random
DESC Two reworked maps where both side's forces are randomised from a set force pool at the start of the mission.
MAKER PipFromSlitherine
TYPE 1
SIZE 1
#URL https://dl.dropbox.com/s/t58tchzkh9v7mff/BETA_Slith_MP_Random.CPF?dl=1

Dropbox specific note: the ?dl=1 addition to the Dropbox URL - this is necessary for a direct download of the file, otherwise the URL will take you to a page with a download link.

Pro tip! If you use a URL shortening service (such as bit.ly or tinyurl) to point to your LST file then it makes is easier for users to enter.

Script: Object reaction functions: SCRIPT_REACT and SCRIPT_USER_VALUE

This allows objects to attempt to react to unit movement/firing in the same way that other units can. One obvious application is for mines or boobytraps.

To turn on reaction scripting for an object you add the following lines to the object entry in the OBJECTS.TXT file.

SCRIPT_REACT <functionName>
SCRIPT_USER_VALUE <value>

The SCRIPT_REACT line defines which function will be called for this object. SCRIPT_USER is optional and can be used to pass in a value to the denoted function. The function itself must be defined in an OBJECTS.BSF file in the same folder as the objects (of course this file can include any shared scripts that you may need from the normal script folders).

The function itself, defined in the OBJECTS.BSF file, can have any of the following parameters

FUNCTION Object_ExampleFunction( tilex, tiley, unit, objectid, objectx, objecty, check, user)
{
}

Only the check parameter is required and its value is set by the game when it calls the function, all others are optional. The function must perform two actions, depending on the value of the check parameter.

When check is non-zero, then the function should return a score determining when the reaction will take place. The highest scoring reacting unit or object reacts first. Reactions then continue in order, up to the point where the target object is dead. Returning -1 means that the object does not wish to react at this time.

When check is zero, it means that we are actually executing the reaction against the target. You can then do whatever action is required, be it offensive or simply triggering an alarm.

The other parameters are:
TILEX - the x tile of the target unit
TILEY - the y tile of the target unit
UNIT - the id of the target unit
OBJECTID - the id of the reacting object
OBJECTX - the tile x of the reacting object
OBJECTY - the tile y of the reacting object
USER - any passed in SCRIPT_USER_VALUE value from the object, otherwise 0

A simple example of an object script is

FUNCTION Object_Bang(objectid, tilex, tiley, objectx, objecty, check, user, unit)
{
int ret ;
 
	// is the object on our tile?
	if( tilex == objectx && tiley == objecty )
	{
		if( check != 0 )
		{
			// return a high score - we always react
			ret = 1000 ;
		}
		else
		{
			// blast 'em!
			ArtilleryFire(tilex, tiley, "USArt", GetBonusValue("MarkerID", GetCurrentSide(), "USArt")) ;
		}
	}
 
	return ret ;
}

Script: multiple scratch arrays, and ability to sort them

New commands allow you to access multiple scratch arrays. You can also sort these arrays, using one as the array to sort, but sorting others into the same order.

ClearArray(value, [array])
Clear out the work array to the specified value. There are 4 arrays, array 0 is used if none is specified. The work array is a set of 256 ints which can be used as a scratchpad. Note that all scripts share the same array, so beware of side effects.
GetArray(index, [array])
Get a value from the specified work array.
SetArray(index, value, [array])
Set a value in the work array”)
SortArray(count, sortArray, [array…])
Perform a sort on one or more arrays using the first count entries. Sorts the array in ascending order. If other array indexes are included, keeps them in the same order as the sortArray.

Script: new commands to get/set options values

You can now use the scripts to check or even alter user options. These should be used with caution! These commands are most useful when used with the AdvancedOptions option string. This is used to determine whether the player is using the advanced tooltips or AI, for example.

VP Plugin Custom Victory Conditions & Globals

The VP plugin provides an easy way to place and set up VPs, and some simple victory conditions and UI feedback. But if you want more complex victory conditions, it is possible to both disable the automatic ending of the battle, and to interogate the various plugin values.

To disable the victory processing, make the following call at the start of the battle

SetUniversalVar("Slith_VP_EndBattleLogic", 1) ;

You will now need to call your own checks for victory. There are a number of globals which the VP plugin script maintains, and these can help with this. They are:

VP Ownership

GetScriptGlobal("Slith_VictoryPoints", "VP#5") ;

where the #5 denotes which VP you are interested in, with valid ranges from #0 to #7. Values are -1 (neutral), 0 (player or side 0), or 1 (AI or side 1).

General Values
You can use GetScriptGlobal to get or set the following variables:

VPTeam#0
Determine whether an AI team attempts to attack any VPs not held by their side. A 0 value means they do not, 1 means they do.

VP_MyVPs
How many VPs does side 0 hold.

VP_EnemyVPs
How many VPs does side 1 hold.

VP_Total
How many VPs are on the map in total.

VP_TurnLimit
What turn limit has been set in the plugin.

mod_older_hot.txt · Last modified: 2020/11/01 00:59 (external edit)
 
Except where otherwise noted, content on this wiki is licensed under the following license: Public Domain
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki