2005-03-31 07:15:32 +02:00
// HACK: This replaces the old numPlayers hack to set up a bunch of sample
// players in SP games to show off some player colours and fights
function setupSPPlayers ( )
2005-01-31 19:58:15 +01:00
{
2005-03-31 07:15:32 +02:00
// The first player is by default allocated to the local player in SP, so
// adding 7 players means that we'll have 8 players in total
for ( i = 0 ; i < 7 ; i ++ )
{
g _GameAttributes . slots [ i + 1 ] . assignLocal ( ) ;
console . write ( "Slot " + ( i + 1 ) + " is assigned: " + g _GameAttributes . slots [ i + 1 ] . assignment ) ;
}
}
2005-01-31 19:58:15 +01:00
2005-03-31 07:15:32 +02:00
function startLoadingScreen ( )
{
2005-01-31 19:58:15 +01:00
// Switch screens from main menu to loading screen.
GUIObjectHide ( "PREGAME_GUI" ) ;
GUIObjectUnhide ( "loading_screen" ) ;
console . write ( "Loading " + g _GameAttributes . mapFile + " (" + g _GameAttributes . numPlayers + " players) ..." ) ;
2005-03-16 15:55:16 +01:00
// Generate random number for random concept art (should be depending on the selected civ later)
randvar = getRandom ( 1 , 6 ) ;
switch ( randvar ) {
case 1 :
sprite = "load_concept_he" ;
break ;
case 2 :
sprite = "load_concept_ce" ;
break ;
case 3 :
sprite = "load_concept_pe" ;
break ;
case 4 :
sprite = "load_concept_ro" ;
break ;
case 5 :
sprite = "load_concept_ca" ;
break ;
case 6 :
sprite = "load_concept_ib" ;
break ;
}
getGUIObjectByName ( "loading_screen_background_concept" ) . sprite = sprite ;
console . write ( getGUIObjectByName ( "loading_screen_background_concept" ) . sprite ) ;
2005-04-11 22:47:58 +02:00
// janwas: main loop now sets progress / description, but that won't
// happen until the first timeslice completes, so set initial values.
2005-01-31 19:58:15 +01:00
getGUIObjectByName ( "loading_screen_titlebar_text" ) . caption = "Loading Scenario ..." ;
2005-04-11 22:47:58 +02:00
getGUIObjectByName ( "loading_screen_progress_bar_text" ) . caption = "" ;
getGUIObjectByName ( "loading_screen_progress_bar" ) . caption = 0 ;
2005-03-30 04:01:22 +02:00
getGUIObjectByName ( "loading_screen_text" ) . caption = "LOADING " + g _GameAttributes . mapFile + " ...\nPlease wait ..." ;
2005-05-05 04:51:39 +02:00
// Pick a random tip of the day (each line is a separate tip).
tipArray = readFileLines ( "gui/text/tips.txt" ) ;
// Set tip string.
getGUIObjectByName ( "loading_screen_tip" ) . caption = tipArray [ getRandom ( 0 , tipArray . length - 1 ) ] ;
2005-01-31 19:58:15 +01:00
// Begin game session.
2005-03-30 04:01:22 +02:00
if ( ! startGame ( ) )
2005-04-11 22:47:58 +02:00
{
// Failed to start the game; go back to the main menu.
GUIObjectHide ( "loading_screen" ) ;
GUIObjectUnhide ( "PREGAME_GUI" ) ;
// Show an error message
btCaptions = new Array ( "OK" ) ;
btCode = new Array ( "" ) ;
messageBox ( 400 , 200 , "The game could not be started with the given parameters. You probably have entered an invalid map name." , "Error" , 0 , btCaptions , btCode ) ;
}
2005-01-31 19:58:15 +01:00
}
// ====================================================================
2005-03-22 03:17:55 +01:00
function reallyStartGame ( )
{
2005-01-31 19:58:15 +01:00
// Create resource pools for each player, etc.
setupSession ( ) ;
FlipGUI ( GUIType ) ;
// Select session peace track.
curr _session _playlist _1 = newRandomSound ( "music" , "peace" ) ;
// Fade out main theme and fade in session theme.
2005-03-22 03:17:55 +01:00
CrossFade ( curr _music , curr _session _playlist _1 , 0.1 ) ;
// janwas: greatly accelerate this timesink;
// will be replaced soon by native version that doesn't block.
2005-01-31 19:58:15 +01:00
// Switch GUI from main menu to game session.
GUIObjectHide ( "loading_screen" ) ;
GUIObjectUnhide ( "SESSION_GUI" ) ;
}
// ====================================================================
function setupSession ( )
{
// Do essentials that can only be done when the session has been loaded ...
// For example, create the resource types.
// Initialise Resource Pools by attaching them to the Player object.
// (CPlayer code takes care of giving a copy to each player.)
2005-04-11 22:47:58 +02:00
CreateResources ( ) ;
2005-01-31 19:58:15 +01:00
// Start refreshing the session controls.
2005-04-22 09:12:55 +02:00
setInterval ( getObjectInfo , 1 , 100 ) ;
2005-01-31 19:58:15 +01:00
}
// ====================================================================
function endSession ( closeType )
{
// Occurs when the player chooses to close the current game.
switch ( closeType )
{
case ( "return" ) :
// If the player has chosen to quit game and return to main menu,
// End the session.
endGame ( ) ;
// Fade out current music and return to playing menu theme.
2005-05-09 06:32:06 +02:00
curr _music = newRandomSound ( 'music' , 'menu' ) ;
CrossFade ( curr _session _playlist _1 , curr _music , 0.1 ) ;
// janwas: greatly accelerate this timesink;
// will be replaced soon by native version that doesn't block.
2005-01-31 19:58:15 +01:00
// Swap GUIs to display main menu.
GUIObjectHide ( 'SESSION_GUI' ) ;
GUIObjectUnhide ( 'PREGAME_GUI' ) ;
break ;
case ( "exit" ) :
// If the player has chosen to shutdown and immediately return to operating system,
exit ( ) ;
break ;
}
}
// ====================================================================