2004-10-16 00:15:31 +02:00
function initSession ( )
{
2004-11-15 01:13:21 +01:00
initGroupPane ( ) ;
2004-11-15 22:07:02 +01:00
initResourcePool ( ) ;
2004-11-16 01:44:10 +01:00
initStatusOrb ( ) ;
2004-11-18 22:27:23 +01:00
initMapOrb ( ) ;
initTeamTray ( ) ;
2004-12-13 02:14:31 +01:00
initSubWindows ( ) ;
2004-11-15 01:13:21 +01:00
}
// ====================================================================
2004-12-18 03:42:22 +01:00
function initCellReference ( )
{
// Define cell reference constants for icon sheets.
// icon_sheet_statistic
stat _accuracy = 0 ;
stat _attack = 1 ;
stat _armour = 2 ;
stat _los = 3 ;
stat _speed = 4 ;
stat _range = 5 ;
stat _hack = 6 ;
stat _pierce = 7 ;
stat _crush = 8 ;
stat _rank1 = 9 ;
stat _rank2 = 10 ;
stat _rank3 = 11 ;
stat _garrison = 12 ;
stat _heart = 13 ;
// portrait_sheet_action
// generic actions
action _empty = 0 ;
action _attack = 1 ;
action _patrol = 2 ;
action _stop = 3 ;
action _gather _food = 4 ;
action _gather _wood = 5 ;
action _gather _stone = 6 ;
action _gather _ore = 7 ;
action _rally = 8 ;
action _repair = 9 ;
action _heal = 10 ;
action _scout = 11 ;
action _townbell = 12 ;
action _lock = 13 ;
action _unlock = 14 ;
// formation actions
action _formation _box = 23 ;
action _formation _column _c = 24 ;
action _formation _column _o = 25 ;
action _formation _line _c = 26 ;
action _formation _line _o = 27 ;
action _formation _phalanx = 28 ;
action _formation _skirmish = 29 ;
action _formation _testudo = 30 ;
action _formation _wedge = 31 ;
// stance actions
action _stance _aggress = 39 ;
action _stance _avoid = 40 ;
action _stance _defend = 41 ;
action _stance _hold = 42 ;
action _stance _stand = 43 ;
// tab actions
action _tab _command = 48 ;
action _tab _train = 49 ;
action _tab _buildciv = 50 ;
action _tab _buildmil = 51 ;
action _tab _research = 52 ;
action _tab _formation = 53 ;
action _tab _stance = 54 ;
action _tab _barter = 55 ;
}
// ====================================================================
2004-12-13 20:14:37 +01:00
function startLoadingScreen ( )
{
// Setup loading screen.
// Switch screens from main menu to loading screen.
GUIObjectHide ( "pregame_gui" ) ;
GUIObjectUnhide ( "loading_screen" ) ;
console . write ( "Loading " + g _GameAttributes . mapFile + " (" + g _GameAttributes . numPlayers + " players) ..." ) ;
2004-12-14 00:15:11 +01:00
getGUIObjectByName ( "loading_screen_titlebar-text" ) . caption = "Loading Scenario ..." ;
getGUIObjectByName ( "loading_screen_progress_bar_text" ) . caption = "... Reticulating splines ..." ;
getGUIObjectByName ( "loading_screen_progress_bar" ) . caption = 80 ;
getGUIObjectByName ( "loading_screen_text" ) . caption = "LOADING " + g _GameAttributes . mapFile + " ...\nPlease wait ...\n(Yes, we know the progress bar doesn't do diddly squat right now)\nJust keep waiting ...\nIt'll get there ...\nAlmost done ...\nTrust me!" ;
getGUIObjectByName ( "loading_screen_tip" ) . caption = "Wise man once say ...\nHe who thinks slow, he act in haste, be rash and quick and foolish. But he that thinks too much, acts too slowly. The stupid always win, Commandersan. Remember that. You are tiny grasshopper." ;
2004-12-13 20:14:37 +01:00
// Begin game session.
setTimeout ( loadSession ( ) , 0 ) ;
}
// ====================================================================
2004-12-12 20:34:38 +01:00
function loadSession ( )
{
startGame ( ) ;
GUIObjectHide ( "loading_screen" ) ;
GUIObjectUnhide ( "session_gui" ) ;
FlipGUI ( GUIType ) ;
2004-12-13 20:14:37 +01:00
2004-12-12 20:34:38 +01:00
// Select session peace track.
curr _session _playlist _1 = newRandomSound ( "music" , "peace" ) ;
// Fade out main theme and fade in session theme.
CrossFade ( curr _music , curr _session _playlist _1 , 0.0001 ) ;
}
// ====================================================================
2004-12-17 18:22:27 +01:00
function setPortrait ( objectName , portraitString , portraitCell )
2004-10-16 00:15:31 +02:00
{
// Use this function as a shortcut to change a portrait object to a different portrait image.
// Accepts an object and specifies its default, rollover (lit) and disabled (grey) sprites.
2004-12-18 03:42:22 +01:00
// Sprite Format: "ui_portrait_"portraitString
// Sprite Format: "ui_portrait_"portraitString"-lit"
// Sprite Format: "ui_portrait_"portraitString"-grey"
2004-10-16 00:15:31 +02:00
// Note: Make sure the file follows this naming convention or bad things could happen.
// Get GUI object
GUIObject = getGUIObjectByName ( objectName ) ;
// Set the three portraits.
2004-12-18 03:42:22 +01:00
GUIObject . sprite = "ui_portrait_" + portraitString ;
2004-11-15 18:34:51 +01:00
// Note we need to use a special syntax here (object["param"] instead of object.param because dashes aren't actually in JS's variable-naming conventions.
2004-10-16 00:15:31 +02:00
GUIObject [ "sprite-over" ] = GUIObject . sprite + "-lit" ;
GUIObject [ "sprite-disabled" ] = GUIObject . sprite + "-grey" ;
2004-12-17 18:22:27 +01:00
// If the source texture is a multi-frame image (icon sheet), specify correct cell.
if ( portraitCell )
2004-12-18 14:32:00 +01:00
GUIObject [ "cell-id" ] = portraitCell ;
2004-10-16 00:15:31 +02:00
}
// ====================================================================
function getObjectInfo ( )
{
// Updated each tick to extract entity information from selected unit(s).
2004-12-03 00:38:51 +01:00
// Don't process GUI when we're full-screen.
if ( GUIType != "none" )
2004-10-16 00:15:31 +02:00
{
2004-12-03 00:38:51 +01:00
if ( ! selection . length ) // If no entity selected,
{
// Hide Status Orb
getGUIObjectByName ( "session_status_orb" ) . hidden = true ;
2004-10-16 00:15:31 +02:00
2004-12-03 00:38:51 +01:00
// Hide Group Pane.
getGUIObjectByName ( "session_group_pane" ) . hidden = true ;
2004-11-12 00:54:41 +01:00
2004-12-03 00:38:51 +01:00
getGlobal ( ) . MultipleEntitiesSelected = 0 ;
}
else // If at least one entity selected,
{
// Store globals for entity information.
// strString = "" + selection[0].position;
// EntityPos = strString.substring(20,strString.length-3);
2004-10-16 00:15:31 +02:00
2004-12-03 00:38:51 +01:00
UpdateStatusOrb ( ) ; // (later, we need to base this on the selected unit's stats changing)
2004-10-16 00:15:31 +02:00
2004-12-03 00:38:51 +01:00
// Check if a group of entities selected
if ( selection . length > 1 )
2004-10-16 00:15:31 +02:00
{
2004-12-03 00:38:51 +01:00
// If a group pane isn't already open, and we don't have the same set as last time,
// NOTE: This "if" is an optimisation because the game crawls if this set of processing occurs every frame.
// It's quite possible for the player to select another group of the same size and for it to not be recognised.
// Best solution would be to base this off a "new entities selected" instead of an on-tick.
if (
// getGUIObjectByName("session_group_pane").hidden == true ||
selection . length != getGlobal ( ) . MultipleEntitiesSelected )
{
UpdateGroupPane ( ) ; // (later, we need to base this on the selection changing)
getGlobal ( ) . MultipleEntitiesSelected = selection . length ;
}
}
else
{
getGlobal ( ) . MultipleEntitiesSelected = 0 ;
2004-10-16 00:15:31 +02:00
2004-12-03 00:38:51 +01:00
// Hide Group Pane.
getGUIObjectByName ( "session_group_pane" ) . hidden = true ;
}
}
2004-10-16 00:15:31 +02:00
2004-12-03 00:38:51 +01:00
// Modify any resources given/taken (later, we need to base this on a resource-changing event).
UpdateResourcePool ( ) ;
2004-11-20 22:52:41 +01:00
2004-12-03 00:38:51 +01:00
// Update Team Tray (later, we need to base this on the player creating a group).
UpdateTeamTray ( ) ;
}
2004-10-16 00:15:31 +02:00
}
// ====================================================================
function MakeUnit ( x , y , z , MakeUnitName )
{
// Spawn an entity at the given coordinates.
DudeSpawnPoint = new Vector3D ( x , y , z ) ;
new Entity ( getEntityTemplate ( MakeUnitName ) , DudeSpawnPoint , 1.0 ) ;
// writeConsole(MakeUnitName + " created at " + DudeSpawnPoint);
}
// ====================================================================
function selected ( )
{
// Returns how many units selected.
if ( selection . length > 0 )
return ( selection [ 0 ] ) ;
return ( null ) ;
}