Difference between revisions of "Scripting"

From theFarWilds
Jump to: navigation, search
 
(12 intermediate revisions by 3 users not shown)
Line 1: Line 1:
This is the start of the scripting API. It will be expanded over time. If you want something ask for it in the forum. Create your scripts here: [http://thefarwilds.com/story/login.html].
+
[[Category:Scripts]]
Scripts are written in [http://www.angelcode.com/angelscript/sdk/docs/manual/index.html AngelScript], it has syntax similar to C.
+
Scripts are written in [http://www.angelcode.com/angelscript/sdk/docs/manual/index.html AngelScript] (current used version is 2.26.2), it has syntax similar to C. Create your scripts [http://story.thefarwilds.com/login.html here].  If you want something ask for it in the [http://thefarwilds.com/forum/viewforum.php?f=14 forum].
----
+
  
Functions you can implement:
+
The scripts you write interact with the game via a collection of [[Hook Functions]].  These hook functions are called by the game at the appropriate times and execute your code.  See the [[#Examples]] section for more details.
  
void configGame();
+
== API ==
// Sets up the game state such as # of players, Map Size, if they need to set a deck or not, etc
+
* [[Preprocessor]]
+
* [[Hook Functions]]
void beforeStart();
+
* [[Global Functions]]
// Do things here before any action. Place creatures and buildings, change their decks etc.
+
* [[Config Functions]]
+
* [[Player Functions]]
void onNewRound();
+
* [[Entity Functions]]
// called after all the new round events
+
* [[Location Functions]]
 +
* [[DlgBox Functions]]
 +
* [[Card Functions]]
 +
* [[Action Functions]]
  
void afterAction(); // not yet
+
== Examples ==
+
[[Scripting Examples]]
void playersTurn(Player player);  // not yet
+
+
bool canPass(Player player); // not yet
+
// called when the real players try to pass.
+
// This is so you can ensure they do a particular action before passing.
+
 
+
 
+
Functions you can call:
+
Entity createEntity(string CardName, int x_coord , int y_coord,Player controller );
+
Entity createEntity(string CardName ,Location loc,Player controller);
+
Entity createEntity(string CardName ,Location loc);
+
Location createLocation(int x,int y);
+
Player getAIPlayer(int index)
+
Player getHumanPlayer(int index)
+
void setTerrain(Location loc,int topo,int veg)
+
int getTopo(Location loc);
+
int getVeg(Location loc);
+
// topo: ocean=1, soggy=2, flat=3, hills=4, mountain=5
+
// veg: desert=1 ,grass=2 ,forest=3
+
 
+
Config Game Functions (you can only call these from inside configGame():
+
void addAIPlayer(string PlayerName,string Avatar,int teamID);
+
// all parameters are ignored for now
+
void setMapSize(int x,int y)
+
// 3 to 17
+
void setNumPlayers(int)
+
// from 1 to 4
+
void setGloryGoal(int)
+
void setMapSeed(int seed)
+
// you can set this if you always want the script to be on the same map
+
void setNumFluxWells(int)
+
 
+
 
+
Player Functions:
+
void addToHand(Player,string cardName)
+
void addToDeck(Player,string cardName,int index)
+
Card getDeckCard(Player,int index)
+
Card getHandCard(Player,int index)
+
void removeHandCard(Player,int index)
+
void removeDeckCard(Player,int index)
+
void drawCard(Player)
+
int deckSize(Player)
+
int handSize(Player)
+
void addFlux(Player,int delta)
+
void addGlory(Player,int delta)
+
int getFlux(Player)
+
int getGlory(Player)
+
 
+
 
+
Entity Functions:
+
 
+
----
+
 
+
Example Scripts:
+
 
+
// Fortified AI
+
void configGame()
+
{
+
addAIPlayer("Evil Fish","Crypt Doctor",0);
+
}
+
+
void beforeStart()
+
{
+
Player aiPlayer=getAIPlayer(0);
+
createEntity("Earthworks",6,6,aiPlayer);
+
createEntity("Earthworks",10,10,aiPlayer);
+
createEntity("Axe Captain",6,7,aiPlayer);
+
createEntity("Attrition",-1,-1,aiPlayer);
+
}
+
 
+
// Preset Scenario
+
void configGame()
+
{
+
setMapSeed(12345);
+
addAIPlayer("Evil Fish","Crypt Doctor",0);
+
}
+
+
void beforeStart()
+
{
+
Player aiPlayer=getAIPlayer(0);
+
Player HumanPlayer=getHumanPlayer(0);
+
+
setTerrain(createLocation(6,6),3,2);
+
createEntity("Earthworks",6,6,aiPlayer);
+
createEntity("Dwarven Hall",8,6,aiPlayer);
+
createEntity("Gully Slingers",6,5,aiPlayer);
+
createEntity("Gully Slingers",6,7,aiPlayer);
+
createEntity("Axe Captain",7,5,aiPlayer);
+
createEntity("Axe Captain",7,6,aiPlayer);
+
createEntity("Flux Well",6,6,aiPlayer);
+
createEntity("Attrition",-1,-1,aiPlayer);
+
+
while(handSize(aiPlayer)>0){
+
removeHandCard(aiPlayer,0);
+
}
+
while(deckSize(aiPlayer)>0){
+
removeDeckCard(aiPlayer,0);
+
}
+
+
while(handSize(HumanPlayer)>0){
+
removeHandCard(HumanPlayer,0);
+
}
+
while(deckSize(HumanPlayer)>0){
+
removeDeckCard(HumanPlayer,0);
+
}
+
+
addToHand(HumanPlayer,"Graveyard");
+
addToHand(HumanPlayer,"Red Imp");
+
addToHand(HumanPlayer,"Red Imp");
+
addToHand(HumanPlayer,"Black Plague");
+
addToHand(HumanPlayer,"Crypt Doctor");
+
addToHand(HumanPlayer,"Hypnotic Banshee");
+
addToHand(HumanPlayer,"Nether Plasma");
+
addToHand(HumanPlayer,"Dank Pit");
+
+
addGlory(HumanPlayer,18);
+
}
+
  
 +
== Helpful Hints ==
 
[[Coordinate System]] : Coordinates in TFW are a bit weird. This page explains.
 
[[Coordinate System]] : Coordinates in TFW are a bit weird. This page explains.

Latest revision as of 15:35, 5 June 2013

Scripts are written in AngelScript (current used version is 2.26.2), it has syntax similar to C. Create your scripts here. If you want something ask for it in the forum.

The scripts you write interact with the game via a collection of Hook Functions. These hook functions are called by the game at the appropriate times and execute your code. See the #Examples section for more details.

API

Examples

Scripting Examples

Helpful Hints

Coordinate System : Coordinates in TFW are a bit weird. This page explains.