Пример #1
0
	void Game::goToMap(const String& mapName, const Vector2d& playerPos)
	{
		if(currentMap!=nullptr)
		{
			currentMap->removeEntity(player);
		}
		setCurrentMap(mapName);
		player->x = playerPos.x;
		player->y = playerPos.y;
		currentMap->addEntity(player);
	}
int InGameState::setCurrentMap( MapData p_map )
{
	bool found =  false;
	unsigned int idx = 0;
	while( !found && idx<m_maps.size() )
	{
		if(m_maps[idx].filename == p_map.filename)
			found = true;
	}

	if(found)
		return setCurrentMap(idx);
	else
		return GAME_FAIL;
}
Пример #3
0
bool stageOneShutDown(void)
{
	debug(LOG_WZ, "== stageOneShutDown ==");

	if ( audio_Disabled() == false )
	{
		sound_CheckAllUnloaded();
	}

	proj_Shutdown();

    releaseMission();

	if (!aiShutdown())
	{
		return false;
	}

	if (!objShutdown())
	{
		return false;
	}

	grpShutDown();

	ResearchRelease();

	//free up the gateway stuff?
	gwShutDown();

	shutdownTerrain();

	if (!mapShutdown())
	{
		return false;
	}

	scrShutDown();
	gridShutDown();

	if ( !anim_Shutdown() )
	{
		return false;
	}

	if ( !animObj_Shutdown() )
	{
		return false;
	}

	if (!shutdownScripts())
	{
		return false;
	}

	debug(LOG_TEXTURE, "=== stageOneShutDown ===");
	pie_TexShutDown();
	// no map for the main menu
	setCurrentMap(NULL, 1);
	// Use mod_multiplay as the default (campaign might have set it to mod_singleplayer)
	rebuildSearchPath( mod_multiplay, true );
	pie_TexInit(); // restart it

	initMiscVars();

	return true;
}
Пример #4
0
// load up the data for a level
bool levLoadData(const char* name, char *pSaveName, GAME_TYPE saveType)
{
	LEVEL_DATASET	*psNewLevel, *psBaseData, *psChangeLevel;
	SDWORD			i;
	bool            bCamChangeSaveGame;

	debug(LOG_WZ, "Loading level %s (%s, type %d)", name, pSaveName, (int)saveType);
	if (saveType == GTYPE_SAVE_START || saveType == GTYPE_SAVE_MIDMISSION)
	{
		if (!levReleaseAll())
		{
			debug(LOG_ERROR, "Failed to unload old data");
			return false;
		}
	}

	levelLoadType = saveType;

	// find the level dataset
	psNewLevel = levFindDataSet(name);
	if (psNewLevel == NULL)
	{
		debug(LOG_WZ, "Dataset %s not found - trying to load as WRF", name);
		return levLoadSingleWRF(name);
	}
	debug(LOG_WZ, "** Data set found is %s type %d", psNewLevel->pName, (int)psNewLevel->type);

	/* Keep a copy of the present level name */
	sstrcpy(currentLevelName, name);

	bCamChangeSaveGame = false;
	if (pSaveName && saveType == GTYPE_SAVE_START)
	{
		if (psNewLevel->psChange != NULL)
		{
			bCamChangeSaveGame = true;
			debug(LOG_WZ, "** CAMCHANGE FOUND");
		}
	}

	// select the change dataset if there is one
	psChangeLevel = NULL;
	if (((psNewLevel->psChange != NULL) && (psCurrLevel != NULL)) || bCamChangeSaveGame)
	{
		//store the level name
		debug(LOG_WZ, "Found CAMCHANGE dataset");
		psChangeLevel = psNewLevel;
		psNewLevel = psNewLevel->psChange;
	}

	// ensure the correct dataset is loaded
	if (psNewLevel->type == LDS_CAMPAIGN)
	{
		debug(LOG_ERROR, "Cannot load a campaign dataset (%s)", psNewLevel->pName);
		return false;
	}
	else
	{
		if (psCurrLevel != NULL)
		{
			if ((psCurrLevel->psBaseData != psNewLevel->psBaseData) ||
				(psCurrLevel->type < LDS_NONE && psNewLevel->type  >= LDS_NONE) ||
				(psCurrLevel->type >= LDS_NONE && psNewLevel->type  < LDS_NONE))
			{
				// there is a dataset loaded but it isn't the correct one
				debug(LOG_WZ, "Incorrect base dataset loaded (%p != %p, %d - %d)",
				      psCurrLevel->psBaseData, psNewLevel->psBaseData, (int)psCurrLevel->type, (int)psNewLevel->type);
				if (!levReleaseAll())	// this sets psCurrLevel to NULL
				{
					return false;
				}
			}
			else
			{
				debug(LOG_WZ, "Correct base dataset already loaded.");
			}
		}

		// setup the correct dataset to load if necessary
		if (psCurrLevel == NULL)
		{
			if (psNewLevel->psBaseData != NULL)
			{
				debug(LOG_WZ, "Setting base dataset to load: %s", psNewLevel->psBaseData->pName);
			}
			psBaseData = psNewLevel->psBaseData;
		}
		else
		{
			debug(LOG_WZ, "No base dataset to load");
			psBaseData = NULL;
		}
	}

	setCurrentMap(psNewLevel->pName, psNewLevel->players);
	if (!rebuildSearchPath(psNewLevel->dataDir, true))
	{
		return false;
	}

	// reset the old mission data if necessary
	if (psCurrLevel != NULL)
	{
		debug(LOG_WZ, "Reseting old mission data");
		if (!levReleaseMissionData())
		{
			return false;
		}
	}

	// need to free the current map and droids etc for a save game
	if ((psBaseData == NULL) &&
		(pSaveName != NULL))
	{
		if (!saveGameReset())
		{
			return false;
		}
	}

	// initialise if necessary
	if (psNewLevel->type == LDS_COMPLETE || //psNewLevel->type >= LDS_MULTI_TYPE_START ||
		psBaseData != NULL)
	{
		debug(LOG_WZ, "Calling stageOneInitialise!");
		if (!stageOneInitialise())
		{
			return false;
		}
	}

	// load up a base dataset if necessary
	if (psBaseData != NULL)
	{
		debug(LOG_WZ, "Loading base dataset %s", psBaseData->pName);
		for(i=0; i<LEVEL_MAXFILES; i++)
		{
			if (psBaseData->apDataFiles[i])
			{
				// load the data
				debug(LOG_WZ, "Loading [directory: %s] %s ...", PHYSFS_getRealDir(psBaseData->apDataFiles[i]), psBaseData->apDataFiles[i]);
				if (!resLoad(psBaseData->apDataFiles[i], i))
				{
					return false;
				}
			}
		}
	}
	if (psNewLevel->type == LDS_CAMCHANGE)
	{
		if (!campaignReset())
		{
			return false;
		}
	}
	if (psNewLevel->game == -1)  //no .gam file to load - BETWEEN missions (for Editor games only)
	{
		ASSERT( psNewLevel->type == LDS_BETWEEN,
			"levLoadData: only BETWEEN missions do not need a .gam file" );
		debug(LOG_WZ, "No .gam file for level: BETWEEN mission");
		if (pSaveName != NULL)
		{
			if (psBaseData != NULL)
			{
				if (!stageTwoInitialise())
				{
					return false;
				}
			}

			//set the mission type before the saveGame data is loaded
			if (saveType == GTYPE_SAVE_MIDMISSION)
			{
				debug(LOG_WZ, "Init mission stuff");
				if (!startMissionSave(psNewLevel->type))
				{
					return false;
				}

				debug(LOG_NEVER, "dataSetSaveFlag");
				dataSetSaveFlag();
			}

			debug(LOG_NEVER, "Loading savegame: %s", pSaveName);
			if (!loadGame(pSaveName, false, true,true))
			{
				return false;
			}
		}

		if ((pSaveName == NULL) ||
			(saveType == GTYPE_SAVE_START))
		{
			debug(LOG_NEVER, "Start mission - no .gam");
			if (!startMission((LEVEL_TYPE)psNewLevel->type, NULL))
			{
				return false;
			}
		}
	}

	//we need to load up the save game data here for a camchange
	if (bCamChangeSaveGame)
	{
		if (pSaveName != NULL)
		{
			if (psBaseData != NULL)
			{
				if (!stageTwoInitialise())
				{
					return false;
				}
			}

			debug(LOG_NEVER, "loading savegame: %s", pSaveName);
			if (!loadGame(pSaveName, false, true,true))
			{
				return false;
			}

			if (!campaignReset())
			{
				return false;
			}
		}
	}


	// load the new data
	debug(LOG_NEVER, "Loading mission dataset: %s", psNewLevel->pName);
	for(i=0; i < LEVEL_MAXFILES; i++)
	{
		if (psNewLevel->game == i)
		{
			// do some more initialising if necessary
			if (psNewLevel->type == LDS_COMPLETE || psNewLevel->type >= LDS_MULTI_TYPE_START || (psBaseData != NULL && !bCamChangeSaveGame))
			{
				if (!stageTwoInitialise())
				{
					return false;
				}
			}

			// load a savegame if there is one - but not if already done so
			if (pSaveName != NULL && !bCamChangeSaveGame)
			{
				//set the mission type before the saveGame data is loaded
				if (saveType == GTYPE_SAVE_MIDMISSION)
				{
					debug(LOG_WZ, "Init mission stuff");
					if (!startMissionSave(psNewLevel->type))
					{
						return false;
					}

					debug(LOG_NEVER, "dataSetSaveFlag");
					dataSetSaveFlag();
				}

				debug(LOG_NEVER, "Loading save game %s", pSaveName);
				if (!loadGame(pSaveName, false, true,true))
				{
					return false;
				}
			}

			if ((pSaveName == NULL) ||
				(saveType == GTYPE_SAVE_START))
			{
				// load the game
				debug(LOG_WZ, "Loading scenario file %s", psNewLevel->apDataFiles[i]);
				switch (psNewLevel->type)
				{
				case LDS_COMPLETE:
				case LDS_CAMSTART:
					debug(LOG_WZ, "LDS_COMPLETE / LDS_CAMSTART");
					if (!startMission(LDS_CAMSTART, psNewLevel->apDataFiles[i]))
					{
						return false;
					}
					break;
				case LDS_BETWEEN:
					debug(LOG_WZ, "LDS_BETWEEN");
					if (!startMission(LDS_BETWEEN, psNewLevel->apDataFiles[i]))
					{
						return false;
					}
					break;

				case LDS_MKEEP:
					debug(LOG_WZ, "LDS_MKEEP");
					if (!startMission(LDS_MKEEP, psNewLevel->apDataFiles[i]))
					{
						return false;
					}
					break;
				case LDS_CAMCHANGE:
					debug(LOG_WZ, "LDS_CAMCHANGE");
					if (!startMission(LDS_CAMCHANGE, psNewLevel->apDataFiles[i]))
					{
						return false;
					}
					break;

				case LDS_EXPAND:
					debug(LOG_WZ, "LDS_EXPAND");
					if (!startMission(LDS_EXPAND, psNewLevel->apDataFiles[i]))
					{
						return false;
					}
					break;
				case LDS_EXPAND_LIMBO:
					debug(LOG_WZ, "LDS_LIMBO");
					if (!startMission(LDS_EXPAND_LIMBO, psNewLevel->apDataFiles[i]))
					{
						return false;
					}
					break;

				case LDS_MCLEAR:
					debug(LOG_WZ, "LDS_MCLEAR");
					if (!startMission(LDS_MCLEAR, psNewLevel->apDataFiles[i]))
					{
						return false;
					}
					break;
				case LDS_MKEEP_LIMBO:
					debug(LOG_WZ, "LDS_MKEEP_LIMBO");
					if (!startMission(LDS_MKEEP_LIMBO, psNewLevel->apDataFiles[i]))
					{
						return false;
					}
					break;
				default:
					ASSERT( psNewLevel->type >= LDS_MULTI_TYPE_START,
						"levLoadData: Unexpected mission type" );
					debug(LOG_WZ, "default (MULTIPLAYER)");
					if (!startMission(LDS_CAMSTART, psNewLevel->apDataFiles[i]))
					{
						return false;
					}
					break;
				}
			}
		}
		else if (psNewLevel->apDataFiles[i])
		{
			// load the data
			debug(LOG_WZ, "Loading %s", psNewLevel->apDataFiles[i]);
			if (!resLoad(psNewLevel->apDataFiles[i], i + CURRENT_DATAID))
			{
				return false;
			}
		}
	}

	if (pSaveName != NULL)
	{
		//load MidMission Extras
		if (!loadMissionExtras(pSaveName, psNewLevel->type))
		{
			return false;
		}
	}

	if (bMultiPlayer)
	{
		loadMultiScripts();
	}
	if (pSaveName != NULL && saveType == GTYPE_SAVE_MIDMISSION)
	{
		//load script stuff
		// load the event system state here for a save game
		debug(LOG_SAVE, "Loading script system state");
		if (!loadScriptState(pSaveName))
		{
			return false;
		}
	}

	if (!stageThreeInitialise())
	{
		return false;
	}

	dataClearSaveFlag();

	//this enables us to to start cam2/cam3 without going via a save game and get the extra droids
	//in from the script-controlled Transporters
	if (!pSaveName && psNewLevel->type == LDS_CAMSTART)
	{
		eventFireCallbackTrigger((TRIGGER_TYPE)CALL_NO_REINFORCEMENTS_LEFT);
	}

	//restore the level name for comparisons on next mission load up
	if (psChangeLevel == NULL)
	{
		psCurrLevel = psNewLevel;
	}
	else
	{
		psCurrLevel = psChangeLevel;
	}

	{
		// Copy this info to be used by the crash handler for the dump file
		char buf[256];

		ssprintf(buf, "Current Level/map is %s", psCurrLevel->pName);
		addDumpInfo(buf);
	}


	return true;
}
Пример #5
0
// ////////////////////////////////////////////////////////////////////////////
// options for a game. (usually recvd in frontend)
void recvOptions(NETQUEUE queue)
{
    unsigned int i;

    debug(LOG_NET, "Receiving options from host");
    NETbeginDecode(queue, NET_OPTIONS);

    // Get general information about the game
    NETuint8_t(&game.type);
    NETstring(game.map, 128);
    NETbin(game.hash.bytes, game.hash.Bytes);
    NETuint8_t(&game.maxPlayers);
    NETstring(game.name, 128);
    NETuint32_t(&game.power);
    NETuint8_t(&game.base);
    NETuint8_t(&game.alliance);
    NETbool(&game.scavengers);

    for (i = 0; i < MAX_PLAYERS; i++)
    {
        NETuint8_t(&game.skDiff[i]);
    }

    // Send the list of who is still joining
    for (i = 0; i < MAX_PLAYERS; i++)
    {
        NETbool(&ingame.JoiningInProgress[i]);
    }

    // Alliances
    for (i = 0; i < MAX_PLAYERS; i++)
    {
        unsigned int j;

        for (j = 0; j < MAX_PLAYERS; j++)
        {
            NETuint8_t(&alliances[i][j]);
        }
    }
    netPlayersUpdated = true;

    // Free any structure limits we may have in-place
    if (ingame.numStructureLimits)
    {
        ingame.numStructureLimits = 0;
        free(ingame.pStructureLimits);
        ingame.pStructureLimits = NULL;
    }

    // Get the number of structure limits to expect
    NETuint32_t(&ingame.numStructureLimits);
    debug(LOG_NET, "Host is sending us %u structure limits", ingame.numStructureLimits);
    // If there were any changes allocate memory for them
    if (ingame.numStructureLimits)
    {
        ingame.pStructureLimits = (MULTISTRUCTLIMITS *)malloc(ingame.numStructureLimits * sizeof(MULTISTRUCTLIMITS));
    }

    for (i = 0; i < ingame.numStructureLimits; i++)
    {
        NETuint32_t(&ingame.pStructureLimits[i].id);
        NETuint32_t(&ingame.pStructureLimits[i].limit);
    }
    NETuint8_t(&ingame.flags);

    NETend();

    // Do the skirmish slider settings if they are up
    for (i = 0; i < MAX_PLAYERS; i++)
    {
        if (widgGetFromID(psWScreen, MULTIOP_SKSLIDE + i))
        {
            widgSetSliderPos(psWScreen, MULTIOP_SKSLIDE + i, game.skDiff[i]);
        }
    }
    debug(LOG_INFO, "Rebuilding map list");
    // clear out the old level list.
    levShutDown();
    levInitialise();
    setCurrentMap(NULL, 42);
    rebuildSearchPath(mod_multiplay, true);	// MUST rebuild search path for the new maps we just got!
    buildMapList();
    // See if we have the map or not
    if (levFindDataSet(game.map, &game.hash) == NULL)
    {
        uint32_t player = selectedPlayer;

        debug(LOG_INFO, "Map was not found, requesting map %s from host.", game.map);
        // Request the map from the host
        NETbeginEncode(NETnetQueue(NET_HOST_ONLY), NET_FILE_REQUESTED);
        NETuint32_t(&player);
        NETend();

        addConsoleMessage("MAP REQUESTED!", DEFAULT_JUSTIFY, SYSTEM_MESSAGE);
    }
    else
    {
        loadMapPreview(false);
    }
}
Пример #6
0
//----------------------------------------------------------------
bool TestScene::onInit (Importer* pkImporter, Renderer* pkRenderer)
{
	std::cout << "HOLA!!!" << std::endl;

	m_pkShape = new Box();
	m_pkPacman = new Sprite();
	m_pkGhost1 = new Sprite();
	m_pkMapa = new Map(pkRenderer);

	pkImporter->importResources("../../res/sprite.xml");

	// create the entities
	m_pkShape->setDim(100,100);
	m_pkShape->setPos(200, 0, 1.0f);
	m_pkShape->setColor(50,100,150);

	// initialize pacman
	if( !pkImporter->createSprite("Pacman", m_pkPacman) )
		return false;

	// set properties
	m_pkPacman->setName("el pacman loco");
	m_pkPacman->setDim(50,50);
	m_pkPacman->setPos(10.0f, 10.0f, 0.0f);
	m_pkPacman->setRotation(0);

	// set animation
	if( m_pkPacman->setAnimation("Eat") )
		m_pkPacman->getAnimation()->play();

	// initialize ghost
	if( !pkImporter->createSprite("Fantasma", m_pkGhost1) )
		return false;

	// set properties
	m_pkGhost1->setName("el fantasma loco");
	m_pkGhost1->setDim(50,50);
	m_pkGhost1->setPos(-100.0f, 0.0f, -1.0f);

	addCollisionGroup("fantasma");
	addCollisionGroup("pacman");
	addCollisionGroup("caja");

	addEntity(m_pkPacman, "pacman");
	addEntity(m_pkGhost1, "fantasma");
	addEntity(m_pkShape, "caja");

	m_pkMapa = new Map(pkRenderer);
	m_pkMapa->loadMap("../../res/MapaPrueba/PruebaPropiaTileset.xml","../../res/MapaPrueba/PruebaPropia.xml");
	m_pkMapa->setPos(500,500);
	//m_pkMapa->setLayerVisible(0,false);
	setCurrentMap(m_pkMapa);

	m_pkMapa->setTile(3,1,1,17);
	m_pkMapa->setTile(2,1,1,0);

	cout << m_pkMapa->getTile(5,4,0) << endl;

	cout << m_pkMapa->getNumCols() << endl;
	cout << m_pkMapa->getNumRows() << endl;
	cout << m_pkMapa->getNumLayers() << endl;
	cout << m_pkMapa->getTileHeight() << endl;
	cout << m_pkMapa->getTileWidth() << endl;

	m_pkFont = new Font(pkRenderer, this);
	m_pkFont->loadFont("../../res/font/font2.fnt");
	m_pkFont->setText("SOMOS LA SAL!-.");
	m_pkFont->setPos(-400,0);

	return true;
}