/**
* game_data.gm
* @author paolo
* @date 2008/12/16
* @brief Put here all the tables and global game variables
*/
//-------------------------------------------------------------
// In game
//-------------------------------------------------------------
//-------------------------------------------------------------
// Temp global, this is a table used to store temp global data,
// use it as you want
// it is good to avoid forgotten global variables everywhere
//-------------------------------------------------------------
global g_temp_globals = {};
//-------------------------------------------------------------
// Game parameters
//-------------------------------------------------------------
local load_params = function( a_filename )
{
system.Compile( g_script_path + "game_settings/" + a_filename, true );
WaitInit( a_filename );
return GetInitResult_Cleanup( a_filename );
};
//-------------------------------------------------------------
// Game global data
//-------------------------------------------------------------
global g_global_info =
{
savefile_version_hi = 1,
savefile_version_lo = 0,
online = false, // if true the user want go online
save_trigger = false,
save_valid_user = false,
bus_settings = {},
dsp_variation_list = {},
// Current active event list
event_list = {},
event_list_filename = "",
// PLAY SET event list
performance_event_list = {},
performance_event_list_planet_randoms = {},
performance_event_name_to_index = {},
performance_event_list_filename = "",
visualizer_list = array(),
visualizer_list_by_planet = {},
visualizer_planet_list = array_int(),
visualizer_planet_variation_list = {},
visualizer_planet_key = {},
// parameters
params_gem_rumble = load_params( "params_gem_rumble.gm" ),
params_inputs = load_params( "params_inputs.gm" ),
params_menu = load_params( "params_menu.gm" ),
params_visualizer = load_params( "params_visualizer.gm" ),
// saved start
music_volume = 10,
sfx_volume = 10,
screen_size = 100,
no_burn = false,
eula_ok = g_FORCE_EULA_OK,
app_version = "01.00",
// saved end
// Call by mainstate.gm
Release = function()
{
threadKillAll( this );
},
// called when an option is changed
NotifyChanged = function()
{
.TriggerEvent("CHANGED",this);
local sfx_volume = clamp( 0.f, .sfx_volume/10.f, 1.f );
local music_volume = clamp( 0.f, .music_volume/10.f, 1.f );
g_sound_mng.SetupUserVolumes( sfx_volume, music_volume );
Q.SetWindowRescale( .screen_size/100.0f );
},
////////////////////////////////////////////////////
// Event list
SetEventDefaultValues = function( a_event )
{
a_event.name ?= "";
a_event.unlock_list ?= {};
a_event.planet_list ?= {};
a_event.planet_random ?= false;
a_event.fadein_effect ?= false;
a_event.ambient ?= "";
a_event.dsp_preset ?= 0;
a_event.k_move_knob_mx ?= 0.0f; a_event.k_move_knob_my ?= 0.0f; a_event.k_move_knob_mz ?= 0.0f; a_event.k_move_knob_mrz ?= 0.0f;
a_event.b_move_knob_mx ?= 0.0f; a_event.b_move_knob_my ?= 0.0f; a_event.b_move_knob_mz ?= 0.0f; a_event.b_move_knob_mrz ?= 0.0f;
a_event.h_move_knob_mx ?= 0.0f; a_event.h_move_knob_my ?= 0.0f; a_event.h_move_knob_mz ?= 0.0f; a_event.h_move_knob_mrz ?= 0.0f;
a_event.s_move_knob_mx ?= 0.0f; a_event.s_move_knob_my ?= 0.0f; a_event.s_move_knob_mz ?= 0.0f; a_event.s_move_knob_mrz ?= 0.0f;
},
SetEventPlanetDefaultValues = function( a_planet )
{
a_planet.type ?= 0;
a_planet.variation ?= 0;
a_planet.fade_color ?= vector4( 1.0f );
// Overwrite planet song
a_planet.overwrite_song_enable ?= false;
a_planet.overwrite_song ?= null;
// -2: no setting, -1: random
a_planet.tracks ?= array
(
{ stem = -2 },
{ stem = -2 },
{ stem = -2 },
{ stem = -2 }
);
},
GenerateDefaultEvent = function()
{
local event = {};
.SetEventDefaultValues( event );
return event;
},
GenerateDefaultEventPlanet = function()
{
local planet = {};
.SetEventPlanetDefaultValues( planet );
return planet;
},
LoadEventList = function( a_filename )
{
local path = "/datacom/" + a_filename + ".gm";
if( Q.FileExists( path ) )
{
local result = system.Compile( path, module_debug );
@@assert( result );
WaitInit( a_filename );
local load_event_list = GetInitResult_Cleanup( a_filename );
@@assert( ?load_event_list );
.performance_event_list = {};
.performance_event_list_planet_randoms = {};
.performance_event_name_to_index = {};
foreach( index and event in load_event_list )
{
.SetEventDefaultValues( event );
@@assert( event.name != "" );
@@assert( !?.performance_event_name_to_index[ event.name ] );
.performance_event_name_to_index[ event.name ] = index;
foreach( planet in event.planet_list )
{
.SetEventPlanetDefaultValues( planet );
}
.performance_event_list[ index ] = event;
if( event.planet_random )
{
.performance_event_list_planet_randoms[ event.name ] = event.name;
}
}
.performance_event_list_filename = a_filename;
// Initialize active event list
.event_list = .performance_event_list;
.event_list_filename = .performance_event_list_filename;
._MakeEventFallback();
}
},
SaveEventList = function( a_filename )
{
local path = "/datacom/" + a_filename + ".gm";
local result = CreateGMFile( path, a_filename, .event_list, null );
@@assert( result );
},
GetEventPlanetName = function( a_event, a_planet_index )
{
local event = .GetEventSafe( a_event );
@@assert( ?event.planet_list[ a_planet_index ] );
return "MASTER_0" + ( event.planet_list[ a_planet_index ].type + 1 );
},
GetEventSafe = function( a_event )
{
a_event ?= -1; // To fallback
local event = .event_list[ a_event ];
event ?= .event_fallback;
return event;
},
GetEventPlanetSafe = function( a_event, a_planet_index )
{
a_planet_index ?= -1; // To fallback
local event = .GetEventSafe( a_event );
local planet = event.planet_list[ a_planet_index ];
planet ?= .event_fallback.planet_list[0];
return planet;
},
GetEventNumPlanets = function( a_event )
{
local event = .GetEventSafe( a_event );
return tableCount( event.planet_list );
},
GetEventIndex = function( a_event_name )
{
local event_list = .event_list;
local event_size = tableCount( event_list );
foreach ( i within 0, event_size )
{
if ( event_list[i].name != a_event_name )
{
continue;
}
return i;
}
return -1;
},
_MakeEventFallback = function()
{
// Base event is first, and all planet selectable.
.event_fallback = TableDuplicateAll( .event_list[0] );
local planet_list = {};
foreach( i within 0, g_MASTER_PLANET_MAX )
{
planet_list[i] = {};
planet_list[i].type = i;
.SetEventPlanetDefaultValues( planet_list[i] );
}
.event_fallback.name = "Fallback";
.event_fallback.planet_list = planet_list;
},
// Visualizer
GenerateVisualizerList = function()
{
local planet_key =
{
1 = "PLANET_HAIR",
2 = "PLANET_KORG",
3 = "PLANET_VORONOI",
4 = "PLANET_ODYSSEY",
5 = "PLANET_BOIDS",
6 = "PLANET_CLASSIC",
};
.visualizer_planet_key = planet_key;
local planet_order =
{
6, 1, 2, 3, 5, 4,
};
local list_by_planet = {};
foreach( event_index and event in .event_list )
{
foreach( planet_index and planet in event.planet_list )
{
list_by_planet[ planet.type ] ?= {};
local list_by_variation = list_by_planet[ planet.type ];
list_by_variation[ planet.variation ] ?=
{
event_index = event_index,
event_planet_index = planet_index,
thumbnail_name = format( "THUMBNAIL_%d_%d", ( planet.type + 1 ), planet.variation ),
visualizer_index = null,
text_key = null,
};
}
}
.visualizer_list_by_planet = list_by_planet;
// Sort
local visualizer_list = array();
local planet_list = array_int();
local planet_variation_list = {};
foreach( type in planet_order )
{
planet_list.PushBack( type );
planet_variation_list[ type ] = array_int();
local list_by_variation = list_by_planet[ type ];
local variation_number = 1;
foreach( variation and data in list_by_variation )
{
data.text_key = planet_key[ type ] + variation_number;
data.visualizer_index = visualizer_list.Size();
visualizer_list.PushBack( data );
variation_number += 1;
planet_variation_list[ type ].PushBack( variation );
}
}
.visualizer_list = visualizer_list;
.visualizer_planet_list = planet_list;
.visualizer_planet_variation_list = planet_variation_list;
/@@
print( "" );
print( "Visualizer list - raw" );
foreach( type and list_by_variation in list_by_planet )
{
foreach( variation and data in list_by_variation )
{
local text = format( "planet %d-%d = { event_index = %d, event_planet_index = %d, thumbnail_name = %s, text_key = %s }", type, variation, data.event_index, data.event_planet_index, data.thumbnail_name, data.text_key );
print( text );
}
}
print( "" );
print( "Visualizer list - ordered" );
foreach( index and data in visualizer_list )
{
local text = format( "%02d: %s = { event_index = %d, event_planet_index = %d, thumbnail_name = %s }", index, data.text_key, data.event_index, data.evebt_planet_index, data.thumbnail_name );
print( text );
}
print( "" );
@@/
},
};
foreach ( track in TrackAlphabetMaster )
{
g_global_info.bus_settings[] = { track = track, bus = {} };
}
global g_4am_Green = g_global_info.params_menu._common_color._4am_Green;
global g_4am_White = g_global_info.params_menu._common_color._4am_White;
global g_4am_CommonMessageColor = g_global_info.params_menu._common_color._4am_CommonMessageColor;
AddEventManager( g_global_info );
global LoadDspVariationList = function()
{
if( Q.FileExists( "/datacom/dsp_variation_list.gm" ) )
{
local result = system.Compile( "/datacom/dsp_variation_list.gm", module_debug );
@@assert( result );
WaitInit( "dsp_variation_list" );
g_global_info.dsp_variation_list = GetInitResult_Cleanup( "dsp_variation_list" );
@@assert( ?g_global_info.dsp_variation_list );
}
};
global SaveDspVariationList = function()
{
local result = CreateGMFile( "/datacom/dsp_variation_list.gm", "dsp_variation_list", g_global_info.dsp_variation_list, null );
@@assert( result );
};
LoadDspVariationList();
global LoadDspBusSettings = function()
{
if( Q.FileExists( "/datacom/dsp_bus_settings.gm" ) )
{
local result = system.Compile( "/datacom/dsp_bus_settings.gm", module_debug );
@@assert( result );
WaitInit( "dsp_bus_settings" );
g_global_info.bus_settings = GetInitResult_Cleanup( "dsp_bus_settings" );
@@assert( ?g_global_info.bus_settings );
}
};
global SaveDspBusSettings = function()
{
local result = CreateGMFile( "/datacom/dsp_bus_settings.gm", "dsp_bus_settings", g_global_info.bus_settings, null );
@@assert( result );
};
LoadDspBusSettings();
g_global_info.LoadEventList( g_TARGET_EVENT_LIST );
g_global_info.GenerateVisualizerList();
// Ingame config from menu
global CreateGameSettings = function()
{
local GameSettings = {};
GameSettings.Reset = function()
{
.player_max = g_PLAYER_MAX;
.event_index = null;
.event_planet_index = null;
.event_planet_index_extracted = null;
.pause = false;
.visualizer_index = 0;
.visualizer_menu_visible = false;
.visualizer_planet_type = -1;
.visualizer_planet_variation = -1;
.visualizer_planet_variation_history = {};
.visualizer_planet_history = array_int();
.visualizer_planet_history_max = 3;
};
GameSettings.IsExistInPlanetHistory = function( a_planet_type )
{
foreach( planet_type in .visualizer_planet_history )
{
if( planet_type == a_planet_type )
{
return true;
}
}
return false;
};
GameSettings.DebugPlanetHistory = function()
{
/@@
foreach( index and planet_type in .visualizer_planet_history )
{
print( format( "%d: %s", index, g_global_info.visualizer_planet_key[ planet_type ] ) );
}
@@/
};
GameSettings.Reset();
return GameSettings;
};
global g_game_settings = CreateGameSettings();