Changed resources over to a player object and did some reorganisation of the session start/end code.
This was SVN commit r1763.
This commit is contained in:
parent
fb69ed56b2
commit
ebfa5f8d24
@ -11,9 +11,6 @@
|
||||
<objects>
|
||||
|
||||
<object type="empty" name="session_gui" hotkey="flipgui.toggle" size="0 0 100% 100%" z="1" hidden="true">
|
||||
<action on="Load"><![CDATA[
|
||||
setInterval( getObjectInfo, 1, 1000 );
|
||||
]]></action>
|
||||
<action on="Press"><![CDATA[
|
||||
FlipGUI();
|
||||
]]></action>
|
||||
@ -1594,7 +1591,7 @@
|
||||
]]></action>
|
||||
<action on="Press"><![CDATA[
|
||||
btCaptions = new Array("Yep, work's done!", "No, more slaughter!");
|
||||
btCode = new Array("endGame();\ncurr_music = newRandomSound('music', 'theme');\nCrossFade(curr_session_playlist_1, curr_music, 0.0001);\nGUIObjectHide('session_gui');\nGUIObjectUnhide('pregame_gui');", "");
|
||||
btCode = new Array("endSession('return');", "");
|
||||
messageBox(600, 200, "Do you want to leave the current game? There might be more dudes to slaughter.", "Confirmation", 0, btCaptions, btCode);
|
||||
]]></action>
|
||||
End Game
|
||||
@ -1610,7 +1607,7 @@
|
||||
]]></action>
|
||||
<action on="Press"><![CDATA[
|
||||
btCaptions = new Array("Yes, let me out!", "Nooooo!");
|
||||
btCode = new Array("exit();", "");
|
||||
btCode = new Array("endSession('exit');", "");
|
||||
messageBox(400, 200, "Do you really want to quit [icon=0ad_icon] A.D.? This will cause a sudden return to reality.", "Confirmation", 0, btCaptions, btCode);
|
||||
]]></action>
|
||||
</object>
|
||||
|
@ -28,7 +28,11 @@ function loadSession()
|
||||
GUIObjectUnhide("pregame_gui");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Create resource pools for each player, etc.
|
||||
setupSession();
|
||||
|
||||
// Switch GUI from main menu to game session.
|
||||
GUIObjectHide("loading_screen");
|
||||
GUIObjectUnhide("session_gui");
|
||||
FlipGUI(GUIType);
|
||||
@ -40,3 +44,55 @@ function loadSession()
|
||||
}
|
||||
|
||||
// ====================================================================
|
||||
|
||||
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.)
|
||||
player = new Object(); // I shouldn't need to do this. Need to find the existing Player to add these to.
|
||||
player.resource = new Object();
|
||||
player.resource.food = 0;
|
||||
player.resource.wood = 0;
|
||||
player.resource.stone = 0;
|
||||
player.resource.ore = 0;
|
||||
player.resource.pop = new Object();
|
||||
player.resource.pop.curr = 0;
|
||||
player.resource.pop.housing = 0;
|
||||
|
||||
// Start refreshing the session controls.
|
||||
setInterval( getObjectInfo, 1, 1000 );
|
||||
}
|
||||
|
||||
// ====================================================================
|
||||
|
||||
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.
|
||||
curr_music = newRandomSound('music', 'theme');
|
||||
CrossFade(curr_session_playlist_1, curr_music, 0.0001);
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
// ====================================================================
|
@ -21,16 +21,6 @@ function initResourcePool()
|
||||
crd_resource_ore_y = crd_resource_stone_y;
|
||||
crd_resource_population_x = crd_resource_ore_x+crd_resource_counter_width+crd_resource_counter_span;
|
||||
crd_resource_population_y = crd_resource_ore_y;
|
||||
|
||||
// Initialise Resource Pools.
|
||||
Resource = new Object();
|
||||
Resource.Food = 0;
|
||||
Resource.Wood = 0;
|
||||
Resource.Stone = 0;
|
||||
Resource.Ore = 0;
|
||||
Resource.Pop = new Object();
|
||||
Resource.Pop.Curr = 0;
|
||||
Resource.Pop.Housing = 0;
|
||||
}
|
||||
|
||||
// ====================================================================
|
||||
@ -42,16 +32,16 @@ function GiveResources(resourceName, resourceQty)
|
||||
switch (resourceName)
|
||||
{
|
||||
case "Food":
|
||||
Resource.Food += resourceQty;
|
||||
player.resource.food += resourceQty;
|
||||
break;
|
||||
case "Wood":
|
||||
Resource.Wood += resourceQty;
|
||||
player.resource.wood += resourceQty;
|
||||
break;
|
||||
case "Stone":
|
||||
Resource.Stone += resourceQty;
|
||||
player.resource.stone += resourceQty;
|
||||
break;
|
||||
case "Ore":
|
||||
Resource.Ore += resourceQty;
|
||||
player.resource.ore += resourceQty;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -64,9 +54,9 @@ function GiveResources(resourceName, resourceQty)
|
||||
|
||||
function UpdateResourcePool()
|
||||
{
|
||||
getGUIObjectByName("resource_food_counter").caption = Resource.Food;
|
||||
getGUIObjectByName("resource_wood_counter").caption = Resource.Wood;
|
||||
getGUIObjectByName("resource_stone_counter").caption = Resource.Stone;
|
||||
getGUIObjectByName("resource_ore_counter").caption = Resource.Ore;
|
||||
getGUIObjectByName("resource_population_counter").caption = Resource.Pop.Curr + "/" + Resource.Pop.Housing;
|
||||
getGUIObjectByName("resource_food_counter").caption = player.resource.food;
|
||||
getGUIObjectByName("resource_wood_counter").caption = player.resource.wood;
|
||||
getGUIObjectByName("resource_stone_counter").caption = player.resource.stone;
|
||||
getGUIObjectByName("resource_ore_counter").caption = player.resource.ore;
|
||||
getGUIObjectByName("resource_population_counter").caption = player.resource.pop.curr + "/" + player.resource.pop.housing;
|
||||
}
|
Loading…
Reference in New Issue
Block a user