Beispiel #1
0
/**
**  Initialize all modules.
**
**  Call each module to initialize.
*/
void InitModules()
{
	GameCycle = 0;
	CDate::CurrentTotalHours = 0;
	FastForwardCycle = 0;
	SyncHash = 0;

	CallbackMusicOn();
	InitSyncRand();
	InitVideoCursors();
	InitUserInterface();
	InitPlayers();
	InitMissileTypes();
	InitMissiles();
	InitConstructions();

	// LUDO : 0 = don't reset player stats ( units level , upgrades, ... ) !
	InitUnitTypes(0);

	InitUnits();
	InitSpells();
	InitUpgrades();

	InitButtons();
	CTrigger::InitActiveTriggers();

	InitAiModule();

	Map.Init();
}
Beispiel #2
0
void RetrieveResources( void )
{
	                            OpeningProgress( 0, 10 );
	InitSound( );				OpeningProgress( 1, 10 );

	InitBackdrop( );			OpeningProgress( 2, 10 );

	GetBlobGraphics( );			OpeningProgress( 3, 10 );
	
	InitNext( );				OpeningProgress( 4, 10 );
	
	InitScore( );				OpeningProgress( 5, 10 );

	InitGrayMonitors( );		OpeningProgress( 6, 10 );
	
	InitOpponent( );			OpeningProgress( 7, 10 );

	InitStage( );   // must run after backdrop window is open
	InitGameTickCount( );

	InitPlayers( ); // must run after backdrop window is open
	InitFont( ); 
	InitZapStyle( );// must run after fonts are inited
					            OpeningProgress( 8, 10 );
	
	InitBlitter( ); // must run after player windows are open
	InitPlayerWorlds( );  		OpeningProgress( 9, 10 );
	
	InitVictory( );	// must run after fonts are inited			
	InitTweak( );				OpeningProgress( 10, 10 );
}
// the initilization function call
void Initilize()
{
	mxhwnd.LoadGraphic(&Background,"bg.bmp"); // load the background image into the MasterGraphic object
	mxhwnd.LoadGraphic(&XGraphic,"x.bmp"); // load the x image into the MasterGraphic object 
	mxhwnd.LoadGraphic(&OGraphic,"o.bmp"); // load the o image into the MasterGraphic object
	mxhwnd.LoadGraphic(&MasterXLogo,"mx.bmp"); // load the MasterX image into the MasterGraphic object
	mxhwnd.LoadSound(&Drop,MAKEINTRESOURCE(IDR_WAVE1));
	mxhwnd.LoadSound(&GameOverSound,MAKEINTRESOURCE(IDR_WAVE2));
	mxhwnd.LoadSound(&CatsGameSound,MAKEINTRESOURCE(IDR_WAVE3));
	ClearBoard();
	mxhwnd.SetScreen(ID_GAME);
	InitPlayers();
}
Beispiel #4
0
/**
**  Load a game to file.
**
**  @param filename  File name to be loaded.
*/
void LoadGame(const std::string &filename)
{
	//Wyrmgus start
	CleanPlayers(); //clean players, as they may not have been cleansed after a scenario
	CurrentCustomHero = nullptr; //otherwise the loaded game will have an extra hero for the current custom hero
	//Wyrmgus end
	
	// log will be enabled if found in the save game
	CommandLogDisabled = true;
	SaveGameLoading = true;

	//Wyrmgus start
//	SetDefaultTextColors(FontYellow, FontWhite);
	SetDefaultTextColors(UI.NormalFontColor, UI.ReverseFontColor);
	//Wyrmgus end
	LoadFonts();
	
	//Wyrmgus start
	InitPlayers();
	//Wyrmgus end

	LuaGarbageCollect();
	InitUnitTypes(1);
	//Wyrmgus start
	CalculateItemsToLoad();
	//Wyrmgus end
	LuaLoadFile(filename);
	LuaGarbageCollect();

	PlaceUnits();

	const unsigned long game_cycle = GameCycle;
	const unsigned long long current_total_hours = CDate::CurrentTotalHours;
	const unsigned syncrand = SyncRandSeed;
	const unsigned synchash = SyncHash;

	InitModules();
	LoadModules();

	GameCycle = game_cycle;
	CDate::CurrentTotalHours = current_total_hours;
	SyncRandSeed = syncrand;
	SyncHash = synchash;
	SelectionChanged();
}
// the window callback function 
// which we passed a pointer to on the CreateMasterX method, this callback function contains a variable called
// msg that we switch and have different case 's for different messages windows sends are program
// like the WM_DESTROY message, this is were we post the quit message to break the while loop
// that we initilized in the InitLoop method.
LRESULT APIENTRY WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
	switch(msg)
	{
	case WM_DESTROY:// called when the window is destroyed
		PostQuitMessage(0);// breaks the while loop
		break;
	case WM_ACTIVATEAPP:
		mxhwnd.activeapp = wParam;// sets the app as active
		break;
	case WM_KEYDOWN:// is sent when a key is pressed
		{
			switch(wParam) // contains the key that was pressed
			{
			case VK_ESCAPE:// when the escape key is pressed
				{
					mxhwnd.Kill();// break the while loop
				}
				break;
			}

			switch(mxhwnd.GetScreen())
			{
			case ID_GAME:
				{
					switch(wParam)
					{
					case VK_RETURN:
						{
							mxhwnd.SetScreen(ID_ABOUT);
						}
						break;
					case VK_SPACE:
						{
							if(GameOver == true)// if the Game is Over then when they press space
							{                   // we wanna Clear the Board, Initilize the Players
								ClearBoard();   // and set GameOver to false
								InitPlayers();
								GameOver = false;
							}
						}
						break;
					}

				}
				break;
			case ID_ABOUT:
				{
					switch(wParam)
					{
					case VK_SPACE:
					case VK_RETURN:
						{
							mxhwnd.SetScreen(ID_GAME);
						}
						break;
					}
				}
				break;
			}

		}
		break;
	case WM_LBUTTONDOWN:// the WM_LBUTTONDOWN, when the left mouse button is clicked
		{
			int x = LOWORD(lParam), y = HIWORD(lParam);

			if(GameOver == false)
			{


			// a if statement to check and see if they clicked within a rectangle
			// if they did then set the Board[0][0] to the Player thats turn it is
			if(x > 50 && x < 160 && y > 130 && y < 200)
			{
				// switch of the Player thats turn it is
				switch(Player)
				{
				case 1:
					{
						if(Board[0][0] == EMPTY)
						{
						Board[0][0] = Player1; // set Board[0][0] to Player1's value
						NextMove();// do the NextMove
						}
					}
					break;
				case 2:
					{
						if(Board[0][0] == EMPTY)
						{
						Board[0][0] = Player2;// set Board[0][0] to Player2's value
						NextMove();// do the NextMove
						}
					}
					break;
				}
			}

			// a if statement to check and see if they clicked within a rectangle
			// if they did then set Board[0][1] to Player thats turn it is
			if(x > 175 && x < 440 && y > 100 && y < 200)
			{
				switch(Player)
				{
				case 1:
					{
						if(Board[0][1] == EMPTY)
						{
						Board[0][1] = Player1;// set Board[0][1] to Player1's value
						NextMove();// do the NextMove
						}
					}
					break;
				case 2:
					{
						if(Board[0][1] == EMPTY)
						{
						Board[0][1] = Player2;// set Board[0][1] to Player2's value
						NextMove();// do the NextMove
						}
					}
					break;
				}

			}


			// a if statement to see if they clicked within a specific rectangle
			// this rectangle is the upper left hand corner of the screen
			// and is were Board[0][2] is drawn 
			if(x > 460 && x < 580 && y > 100 && y < 200)
			{
				switch(Player)
				{
				case 1:
					{
						if(Board[0][2] == EMPTY)
						{
						Board[0][2] = Player1;// set Board[0][2] to Player1's value
						NextMove(); // do the NextMove
						}
					}
					break;
				case 2:
					{
						if(Board[0][2] == EMPTY)
						{
						Board[0][2] = Player2;// set Board[0][2] to Player2's value
						NextMove();// do the NextMove
						}
					}
					break;
				}
			}

			// a if statement to see if they clicked within a rectangle
			// its checking to see if they clicked in the the right middle 
			if(x > 50 && x < 160 && y > 215 && y < 335)
			{
				switch(Player)
				{
				case 1:
					{
						if(Board[1][0] == EMPTY)
						{
						Board[1][0] = Player1;// set Board[1][0] to Player1's value
						NextMove();// do the NextMove
						}
					}
					break;
				case 2:
					{
						if(Board[1][0] == EMPTY)
						{
						Board[1][0] = Player2;// set Board[1][0] to Player2's value
						NextMove();// do the NextMove
						}
					}
					break;
				}

			}

			// a if statement to see if they clicked within a rectangle
			// the rectangle is the center of the screen the center sqaure
			if(x > 175 && x < 445 && y > 220 && y < 335)
			{
				switch(Player)
				{
				case 1:
					{
						if(Board[1][1] == EMPTY)
						{
						Board[1][1] = Player1;// set Board[1][1] to Player1's value
						NextMove();// do the NextMove
						}
					}
					break;
				case 2:
					{
						if(Board[1][1] == EMPTY)
						{
						Board[1][1] = Player2;// set Board[1][1] to Player2's value
						NextMove();// do the NextMove
						}
					}
					break;
				}

			}

			// a if statement to see if they clicked within a rectangle
			// the rectangle is near the middle right of the screen
			if(x > 450 && x < 585 && y > 220 && y < 335)
			{
				switch(Player)
				{
				case 1:
					{
						if(Board[1][2] == EMPTY)
						{
						Board[1][2] = Player1;// set Board[1][2] to Player1's value
						NextMove();// do the NextMove
						}
					}
					break;
				case 2:
					{
						if(Board[1][2] == EMPTY)
						{
						Board[1][2] = Player2;// set Board[1][2] to Player2's value
						NextMove();// do the NextMove
						}
					}
					break;
				}


			}

			// a if statment to see if they clicked within a rectangle
			// the rectangle is near the lower left hand corner of the screen
			if(x > 50 && x < 160 && y > 350 && y < 445)
			{
				switch(Player)
				{
				case 1:
					{
						if(Board[2][0] == EMPTY)
						{
						Board[2][0] = Player1;// set Board[2][0] to Player1's value
						NextMove();// do the NextMove
						}
					}
					break;
				case 2:
					{
						if(Board[2][0] == EMPTY)
						{
						Board[2][0] = Player2;// set Board[2][0] to Player2's value
						NextMove();// do the NextMove
						}
					}
					break;
				}

			}

			// a if statement to see if they clicked within a rectangle
			// the rectangle is near the bottom middle of the screen
			if(x > 175 && x < 445 && y > 350 && y < 430)
			{
				switch(Player)
				{
				case 1:
					{
						if(Board[2][1] == EMPTY)
						{
						Board[2][1] = Player1;//set Board[2][1] to Player1's value
						NextMove();// do the NextMove
						}
					}
					break;
				case 2:
					{
						if(Board[2][1] == EMPTY)
						{
						Board[2][1] = Player2;// set Board[2][1] to Player2's value
						NextMove();// do the NextMove
						}
					}
					break;
				}

			}

			// a if statement to see if they clicked within a rectangle
			// this is to see if they clicked the square in the bottom right hand corner
			if(x > 450 && x < 585 && y > 350 && y < 445)
			{
				switch(Player)
				{
				case 1:
					{
						if(Board[2][2] == EMPTY)
						{
						Board[2][2] = Player1;// set Board[2][2] to Player1's value
						NextMove();// do the NextMove
						}
					}
					break;
				case 2:
					{
						if(Board[2][2] == EMPTY)
						{
						Board[2][2] = Player2;// set Board[2][2] to Player2's value
						NextMove();// do the NextMove
						}
					}
					break;
				}

			}

			}

		}
		break;
	default:
		return DefWindowProc(hwnd,msg,wParam,lParam);// call the default window proccess
	}
	return (0);
}
Beispiel #6
0
/**
**  Load a Stratagus map.
**
**  @param smpname  smp filename
**  @param mapname  map filename
**  @param map      map loaded
*/
static void LoadStratagusMap(const char *smpname, const char *mapname, CMap *map)
{
	char mapfull[PATH_MAX];
	CFile file;

	// Try the same directory as the smp file first
	strcpy_s(mapfull, sizeof(mapfull), smpname);
	char *p = strrchr(mapfull, '/');
	if (!p) {
		p = mapfull;
	} else {
		++p;
	}
	strcpy_s(p, sizeof(mapfull) - (p - mapfull), mapname);

	if (file.open(mapfull, CL_OPEN_READ) == -1) {
		// Not found, try StratagusLibPath and the smp's dir
		strcpy_s(mapfull, sizeof(mapfull), StratagusLibPath.c_str());
		strcat_s(mapfull, sizeof(mapfull), "/");
		strcat_s(mapfull, sizeof(mapfull), smpname);
		char *p = strrchr(mapfull, '/');
		if (!p) {
			p = mapfull;
		} else {
			++p;
		}
		strcpy_s(p, sizeof(mapfull) - (p - mapfull), mapname);
		if (file.open(mapfull, CL_OPEN_READ) == -1) {
			// Not found again, try StratagusLibPath
			strcpy_s(mapfull, sizeof(mapfull), StratagusLibPath.c_str());
			strcat_s(mapfull, sizeof(mapfull), "/");
			strcat_s(mapfull, sizeof(mapfull), mapname);
			if (file.open(mapfull, CL_OPEN_READ) == -1) {
				// Not found, try mapname by itself as a last resort
				strcpy_s(mapfull, sizeof(mapfull), mapname);
			} else {
				file.close();
			}
		} else {
			file.close();
		}
	} else {
		file.close();
	}

	if (LcmPreventRecurse) {
		fprintf(stderr, "recursive use of load Stratagus map!\n");
		ExitFatal(-1);
	}
	InitPlayers();
	LcmPreventRecurse = 1;
	if (LuaLoadFile(mapfull) == -1) {
		fprintf(stderr, "Can't load lua file: %s\n", mapfull);
		ExitFatal(-1);
	}
	LcmPreventRecurse = 0;

#if 0
	// Not true if multiplayer levels!
	if (!ThisPlayer) { /// ARI: bomb if nothing was loaded!
		fprintf(stderr, "%s: invalid Stratagus map\n", mapname);
		ExitFatal(-1);
	}
#endif
	if (!Map.Info.MapWidth || !Map.Info.MapHeight) {
		fprintf(stderr, "%s: invalid Stratagus map\n", mapname);
		ExitFatal(-1);
	}
	Map.Info.Filename = mapname;
}
Beispiel #7
0
/**
**  CreateGame.
**
**  Load map, graphics, sounds, etc
**
**  @param filename  map filename
**  @param map       map loaded
**
**  @todo FIXME: use in this function InitModules / LoadModules!!!
*/
void CreateGame(const char *filename, CMap *map)
{
	int i;

	if (SaveGameLoading) {
		SaveGameLoading = 0;
		// Load game, already created game with Init/LoadModules
		CommandLog(NULL, NoUnitP, FlushCommands, -1, -1, NoUnitP, NULL, -1);
		return;
	}

	InitVisionTable(); // build vision table for fog of war
	InitPlayers();
	
	if (Map.Info.Filename.empty() && filename) {
		char path[PATH_MAX];
		
		Assert(filename);
		LibraryFileName(filename, path, sizeof(path));
		if(strcasestr(filename, ".smp")) {
			LuaLoadFile(path);
		}
	}

	for (i = 0; i < PlayerMax; ++i) {
		int playertype = Map.Info.PlayerType[i];
		// Network games only:
		if (GameSettings.Presets[i].Type != SettingsPresetMapDefault) {
			playertype = GameSettings.Presets[i].Type;
		}
		CreatePlayer(playertype);
	}

	if (filename) {
		if (CurrentMapPath != filename) {
			strcpy_s(CurrentMapPath, sizeof(CurrentMapPath), filename);
		}

		//
		// Load the map.
		//
		InitUnitTypes(1);
		LoadMap(filename, map);
		
		// HARDCODING FOG OF WAR TRUE.  It doesn't currently use preferences on a game restart - Should be changed 
		map->NoFogOfWar = true;
		Map.Reveal();
	}

	GameCycle = 0;
	FastForwardCycle = 0;
	SyncHash = 0;
	InitSyncRand();

	if (IsNetworkGame()) { // Prepare network play
		DebugPrint("Client setup: Calling InitNetwork2\n");
		InitNetwork2();
	} else {
		if (LocalPlayerName && strcmp(LocalPlayerName, "Anonymous")) {
		  ThisPlayer->SetName(LocalPlayerName);
		}
	}

	CallbackMusicOn();

#if 0
	GamePaused = true;
#endif

	if (FlagRevealMap) {
		Map.Reveal();
	}

	//
	// Setup game types
	//
	// FIXME: implement more game types
	if (GameSettings.GameType != SettingsGameTypeMapDefault) {
		switch (GameSettings.GameType) {
			case SettingsGameTypeMelee:
				break;
			case SettingsGameTypeFreeForAll:
				GameTypeFreeForAll();
				break;
			case SettingsGameTypeTopVsBottom:
				GameTypeTopVsBottom();
				break;
			case SettingsGameTypeLeftVsRight:
				GameTypeLeftVsRight();
				break;
			case SettingsGameTypeManVsMachine:
				GameTypeManVsMachine();
				break;
			case SettingsGameTypeManTeamVsMachine:
				GameTypeManTeamVsMachine();

			// Future game type ideas
#if 0
			case SettingsGameTypeOneOnOne:
				break;
			case SettingsGameTypeCaptureTheFlag:
				break;
			case SettingsGameTypeGreed:
				break;
			case SettingsGameTypeSlaughter:
				break;
			case SettingsGameTypeSuddenDeath:
				break;
			case SettingsGameTypeTeamMelee:
				break;
			case SettingsGameTypeTeamCaptureTheFlag:
				break;
#endif
		}
	}

	//
	// Graphic part
	//
	SetPlayersPalette();
	InitIcons();
	LoadIcons();

	LoadCursors(PlayerRaces.Name[ThisPlayer->Race]);
	UnitUnderCursor = NoUnitP;

	InitMissileTypes();
#ifndef DYNAMIC_LOAD
	LoadMissileSprites();
#endif
	InitConstructions();
	LoadConstructions();
	LoadUnitTypes();
	LoadDecorations();

	InitSelections();

	InitUserInterface();
	UI.Load();

	UI.Minimap.Create();
	Map.Init();
	PreprocessMap();

	//
	// Sound part
	//
	LoadUnitSounds();
	MapUnitSounds();
	if (SoundEnabled()) {
		InitSoundClient();
	}

	//
	// Spells
	//
	InitSpells();

	//
	// Init units' groups
	//
	InitGroups();

	//
	// Init players?
	//
	DebugPlayers();
	PlayersInitAi();

	//
	// Upgrades
	//
	InitUpgrades();

	//
	// Dependencies
	//
	InitDependencies();

	//
	// Buttons (botpanel)
	//
	InitButtons();

	//
	// Triggers
	//
	InitTriggers();

	SetDefaultTextColors(UI.NormalFontColor, UI.ReverseFontColor);

#if 0
	if (!UI.SelectedViewport) {
		UI.SelectedViewport = UI.Viewports;
	}
#endif
	UI.SelectedViewport->Center(
		ThisPlayer->StartX, ThisPlayer->StartY, TileSizeX / 2, TileSizeY / 2);

	//
	// Various hacks wich must be done after the map is loaded.
	//
	// FIXME: must be done after map is loaded
	InitAStar();
	//
	// FIXME: The palette is loaded after the units are created.
	// FIXME: This loops fixes the colors of the units.
	//
	for (i = 0; i < NumUnits; ++i) {
		// I don't really think that there can be any rescued
		// units at this point.
		if (Units[i]->RescuedFrom) {
			Units[i]->Colors = &Units[i]->RescuedFrom->UnitColors;
		} else {
			Units[i]->Colors = &Units[i]->Player->UnitColors;
		}
	}

	GameResult = GameNoResult;

	CommandLog(NULL, NoUnitP, FlushCommands, -1, -1, NoUnitP, NULL, -1);
	Video.ClearScreen();
}