void main(void) { int j,k; long xp=6*CELL_WIDTH, yp=6*CELL_HEIGHT,dx,dy, angle = 500; char key; float rad; clrscr(); SetMode(); LoadMap("RayMap.Dat"); Wall = (unsigned char *)malloc(64*64); Wall1 = (unsigned char *)malloc(64*64); ClearScreen(SCREEN); MakeTables(); // get mem for double buffer. VSCREEN = (char far*)farmalloc(64000); Fondo = (char far*)farmalloc(64000); LoadImage(Fondo,"fondo.cel"); LoadImage(Wall,"walltext.cel"); LoadImage(Wall1,"wall1.cel"); InstallKeyboardHandler(); while (!keypress[ESC]) { Dest = VSCREEN; Source = Fondo; ShowPage32(); RayCast(xp,yp,angle); Dest = SCREEN; Source = VSCREEN; ShowPage32(); dx=dy=0; if (keypress[RIGHT]) if ((angle += WorldAngles[6]) > WorldAngles[360]) angle = WorldAngles[0]; if (keypress[LEFT]) if ((angle -=WorldAngles[6]) < WorldAngles[0]) angle = WorldAngles[360]; if (keypress[UP]) { rad = 6.28*angle/WorldAngles[360]; dx=cos(rad)*30; dy=sin(rad)*30; } if (keypress[DOWN]) { rad = 6.28*angle/WorldAngles[360]; dx=-cos(rad)*30; dy=-sin(rad)*30; } // move player xp+=dx; yp+=dy; } RemoveKeyboardHandler(); SetText(); farfree(VSCREEN); farfree(Fondo); FreeTables(); // if (Wall != NULL) free(Wall); free(Wall1); // farfree(Wall1); }
void EditorScreen::DrawToolBar(sf::RenderWindow &Window) { sf::RectangleShape segmentShape; segmentShape.setPosition(0, 0); sf::Vector2<float> segmentSize(1280, 40); segmentShape.setSize(segmentSize); segmentShape.setFillColor(sf::Color(0,0,0,180)); Window.draw(segmentShape); sf::Sprite toolbarSpacer; toolbarSpacer.setTexture(toolbarIconsTex); toolbarSpacer.setTextureRect(sf::Rect<int>(0, 2, 2, 30)); int x = 5; if (DrawButton(Window, x, 5 , 0)) // New Map ResetMap(); x = x + 35; if (DrawButton(Window, x, 5 , 2)) // Save Map SaveMap(); x = x + 35; if (DrawButton(Window, x, 5 , 1)) // Load Map LoadMap(); x = x + 35; if (DrawButton(Window, x, 5 , 3)) // Layer change { layerPane->minimized = !layerPane->minimized; } /*x = x + 35; if (DrawButton(Window, x, 5 , 4)) // Zoom out { map->zoomScale -= 0.05f; if (map->zoomScale < 0.1f) map->zoomScale = 0.1f; } x = x + 35; if (DrawButton(Window, x, 5 , 5)) // Zoom in { map->zoomScale += 0.05; if (map->zoomScale > 2.0f) map->zoomScale = 2.0f; }*/ x = x + 40; toolbarSpacer.setPosition(x, 5); Window.draw(toolbarSpacer, sf::RenderStates::Default); x = x + 10; if (DrawButton(Window, x, 5 , 6)) // Segment drawing mode { drawingMode = (drawingMode_t)SEGMENT_SELECTION; ledgePane->minimized = true; } x = x + 35; if (DrawButton(Window, x, 5 , 7)) // Ledge drawing mode { drawingMode = (drawingMode_t)LEDGES; segmentPane->minimized = true; ledgePane->minimized = false; } x = x + 35; if (DrawButton(Window, x, 5 , 8)) // Collision drawing mode { } x = x + 40; toolbarSpacer.setPosition(x, 5); Window.draw(toolbarSpacer, sf::RenderStates::Default); x = x + 10; if (DrawButton(Window, x, 5 , 9)) // Test map { PlayTestScreen *screen = new PlayTestScreen; screen->SetMapData(map); ScreenManager::GetInstance().AddScreen(screen); } }
bool HeightMapGen::Initialize () { if (!csInitializer::RequestPlugins (object_reg, CS_REQUEST_VFS, CS_REQUEST_PLUGIN("crystalspace.graphics3d.null", iGraphics3D), CS_REQUEST_ENGINE, CS_REQUEST_FONTSERVER, CS_REQUEST_IMAGELOADER, CS_REQUEST_LEVELLOADER, CS_REQUEST_REPORTER, CS_REQUEST_REPORTERLISTENER, CS_REQUEST_PLUGIN("crystalspace.collisiondetection.opcode", iCollideSystem), CS_REQUEST_END)) { csReport (object_reg, CS_REPORTER_SEVERITY_ERROR, "crystalspace.application.heightmapgen", "Can't initialize plugins!"); return false; } // Check for commandline help. if (csCommandLineHelper::CheckHelp (object_reg)) { csCommandLineHelper::Help (object_reg); return false; } // The virtual clock. vc = csQueryRegistry<iVirtualClock> (object_reg); if (!vc) { csReport (object_reg, CS_REPORTER_SEVERITY_ERROR, "crystalspace.application.heightmapgen", "Can't find the virtual clock!"); return false; } // Find the pointer to engine plugin engine = csQueryRegistry<iEngine> (object_reg); if (!engine) { csReport (object_reg, CS_REPORTER_SEVERITY_ERROR, "crystalspace.application.heightmapgen", "No iEngine plugin!"); return false; } loader = csQueryRegistry<iLoader> (object_reg); if (!loader) { csReport (object_reg, CS_REPORTER_SEVERITY_ERROR, "crystalspace.application.heightmapgen", "No iLoader plugin!"); return false; } g3d = csQueryRegistry<iGraphics3D> (object_reg); if (!g3d) { csReport (object_reg, CS_REPORTER_SEVERITY_ERROR, "crystalspace.application.heightmapgen", "No iGraphics3D plugin!"); return false; } kbd = csQueryRegistry<iKeyboardDriver> (object_reg); if (!kbd) { csReport (object_reg, CS_REPORTER_SEVERITY_ERROR, "crystalspace.application.heightmapgen", "No iKeyboardDriver plugin!"); return false; } // Open the main system. This will open all the previously loaded plug-ins. if (!csInitializer::OpenApplication (object_reg)) { csReport (object_reg, CS_REPORTER_SEVERITY_ERROR, "crystalspace.application.heightmapgen", "Error opening system!"); return false; } csRef<iCommandLineParser> cmdline = csQueryRegistry<iCommandLineParser> (object_reg); const char* configfile = cmdline->GetName (0); if (!configfile) { csReport (object_reg, CS_REPORTER_SEVERITY_ERROR, "crystalspace.application.heightmapgen", "Expected name of a config file as a parameter!"); return false; } config.AddConfig (object_reg, configfile); cfgmgr = (iConfigFile*)config; if (!LoadMap ()) return false; return true; }
CCastleGame::CCastleGame(char* szInitialMap) { LoadMap(szInitialMap); }
// Load new map bool j1Map::Load(const char* file_name) { bool ret = true; p2SString tmp("%s%s", folder.GetString(), file_name); char* buf; int size = App->fs->Load(tmp.GetString(), &buf); pugi::xml_parse_result result = map_file.load_buffer(buf, size); RELEASE(buf); if(result == NULL) { LOG("Could not load map xml file %s. pugi error: %s", file_name, result.description()); ret = false; } // Load general info ---------------------------------------------- if(ret == true) { ret = LoadMap(); } // Load all tilesets info ---------------------------------------------- pugi::xml_node tileset; for(tileset = map_file.child("map").child("tileset"); tileset && ret; tileset = tileset.next_sibling("tileset")) { TileSet* set = new TileSet(); if(ret == true) { ret = LoadTilesetDetails(tileset, set); } if(ret == true) { ret = LoadTilesetImage(tileset, set); } data.tilesets.add(set); } // Load layer info ---------------------------------------------- pugi::xml_node layer; for(layer = map_file.child("map").child("layer"); layer && ret; layer = layer.next_sibling("layer")) { MapLayer* lay = new MapLayer(); ret = LoadLayer(layer, lay); if(ret == true) data.layers.add(lay); } if(ret == true) { LOG("Successfully parsed map XML file: %s", file_name); LOG("width: %d height: %d", data.width, data.height); LOG("tile_width: %d tile_height: %d", data.tile_width, data.tile_height); p2List_item<TileSet*>* item = data.tilesets.start; while(item != NULL) { TileSet* s = item->data; LOG("Tileset ----"); LOG("name: %s firstgid: %d", s->name.GetString(), s->firstgid); LOG("tile width: %d tile height: %d", s->tile_width, s->tile_height); LOG("spacing: %d margin: %d", s->spacing, s->margin); item = item->next; } p2List_item<MapLayer*>* item_layer = data.layers.start; while(item_layer != NULL) { MapLayer* l = item_layer->data; LOG("Layer ----"); LOG("name: %s", l->name.GetString()); LOG("tile width: %d tile height: %d", l->width, l->height); item_layer = item_layer->next; } } map_loaded = ret; return ret; }
void Battle::FixTeamIDs( BalanceType balance_type, bool support_clans, bool strong_clans, int numcontrolteams ) { wxLogMessage(_T("Autobalancing teams, type=%d, clans=%d, strong_clans=%d, numcontrolteams=%d"),balance_type, support_clans, strong_clans, numcontrolteams); //size_t i; //int num_alliances; std::vector<ControlTeam> control_teams; if ( numcontrolteams == 0 || numcontrolteams == -1 ) numcontrolteams = GetNumUsers() - GetSpectators(); // 0 or -1 -> use num players, will use comshare only if no available team slots IBattle::StartType position_type = (IBattle::StartType)s2l( CustomBattleOptions().getSingleValue( _T("startpostype"), OptionsWrapper::EngineOption ) ); if ( ( position_type == ST_Fixed ) || ( position_type == ST_Random ) ) // if fixed start pos type or random, use max teams = start pos count { try { int mapposcount = LoadMap().info.positions.size(); numcontrolteams = std::min( numcontrolteams, mapposcount ); } catch( assert_exception ) {} } if ( numcontrolteams >= (int)( GetNumUsers() - GetSpectators() ) ) // autobalance behaves weird when trying to put one player per team and i CBA to fix it, so i'll reuse the old code :P { // apparently tasserver doesnt like when i fix/force ids of everyone. std::set<int> allteams; size_t numusers = GetNumUsers(); for( size_t i = 0; i < numusers; ++i ) { User &user = GetUser(i); if( !user.BattleStatus().spectator ) allteams.insert( user.BattleStatus().team ); } std::set<int> teams; int t = 0; for( size_t i = 0; i < GetNumUsers(); ++i ) { User &user = GetUser(i); if( !user.BattleStatus().spectator ) { if( teams.count( user.BattleStatus().team ) ) { while( allteams.count(t) || teams.count( t ) ) t++; ForceTeam( GetUser(i), t ); teams.insert( t ); } else { teams.insert( user.BattleStatus().team ); } } } return; } for ( int i = 0; i < numcontrolteams; i++ ) control_teams.push_back( ControlTeam( i ) ); wxLogMessage(_T("number of teams: %u"), control_teams.size() ); std::vector<User*> players_sorted; players_sorted.reserve( GetNumUsers() ); int player_team_counter = 0; for ( size_t i = 0; i < GetNumUsers(); ++i ) // don't count spectators { if ( !GetUser(i).BattleStatus().spectator ) { players_sorted.push_back( &GetUser(i) ); // -- server fail? it doesnt work right. //ForceTeam(GetUser(i),player_team_counter); player_team_counter++; } } shuffle( players_sorted ); std::map<wxString, ControlTeam> clan_teams; if ( support_clans ) { for ( size_t i = 0; i < players_sorted.size(); ++i ) { wxString clan = players_sorted[i]->GetClan(); if ( !clan.empty() ) { clan_teams[clan].AddPlayer( players_sorted[i] ); } } }; if ( balance_type != balance_random ) std::sort( players_sorted.begin(), players_sorted.end(), PlayerRankCompareFunction ); if ( support_clans ) { std::map<wxString, ControlTeam>::iterator clan_it = clan_teams.begin(); while ( clan_it != clan_teams.end() ) { ControlTeam &clan = (*clan_it).second; // if clan is too small (only 1 clan member in battle) or too big, dont count it as clan if ( ( clan.players.size() < 2 ) || ( !strong_clans && ( clan.players.size() > ( ( players_sorted.size() + control_teams.size() -1 ) / control_teams.size() ) ) ) ) { wxLogMessage(_T("removing clan %s"),(*clan_it).first.c_str()); std::map<wxString, ControlTeam>::iterator next = clan_it; ++next; clan_teams.erase( clan_it ); clan_it = next; continue; } wxLogMessage( _T("Inserting clan %s"), (*clan_it).first.c_str() ); std::sort( control_teams.begin(), control_teams.end() ); float lowestrank = control_teams[0].ranksum; int rnd_k = 1; // number of alliances with rank equal to lowestrank while ( size_t( rnd_k ) < control_teams.size() ) { if ( fabs( control_teams[rnd_k].ranksum - lowestrank ) > 0.01 ) break; rnd_k++; } wxLogMessage(_T("number of lowestrank teams with same rank=%d"), rnd_k ); control_teams[my_random( rnd_k )].AddTeam( clan ); ++clan_it; } } for (size_t i = 0; i < players_sorted.size(); ++i ) { // skip clanners, those have been added already. if ( clan_teams.count( players_sorted[i]->GetClan() ) > 0 ) { wxLogMessage( _T("clanner already added, nick=%s"),players_sorted[i]->GetNick().c_str() ); continue; } // find teams with lowest ranksum // insert current user into random one out of them // since performance doesnt matter here, i simply sort teams, // then find how many teams in beginning have lowest ranksum // note that balance player ranks range from 1 to 1.1 now // i.e. them are quasi equal // so we're essentially adding to teams with smallest number of players, // the one with smallest ranksum. std::sort( control_teams.begin(), control_teams.end() ); float lowestrank = control_teams[0].ranksum; int rnd_k = 1; // number of alliances with rank equal to lowestrank while ( size_t( rnd_k ) < control_teams.size() ) { if ( fabs ( control_teams[rnd_k].ranksum - lowestrank ) > 0.01 ) break; rnd_k++; } wxLogMessage( _T("number of lowestrank teams with same rank=%d"), rnd_k ); control_teams[my_random( rnd_k )].AddPlayer( players_sorted[i] ); } for ( size_t i=0; i < control_teams.size(); ++i ) { for ( size_t j = 0; j < control_teams[i].players.size(); ++j ) { ASSERT_LOGIC( control_teams[i].players[j], _T("fail in Autobalance teams, NULL player") ); wxString msg = wxFormat( _T("setting player %s to team and ally %d") ) % control_teams[i].players[j]->GetNick() % i; wxLogMessage( _T("%s"), msg.c_str() ); ForceTeam( *control_teams[i].players[j], control_teams[i].teamnum ); ForceAlly( *control_teams[i].players[j], control_teams[i].teamnum ); } } }
void CGameManager::LoadSave(int nSlot) { Reset(); wchar_t path[MAX_PATH]; HRESULT hr = SHGetFolderPathW(0, CSIDL_APPDATA, 0, SHGFP_TYPE_CURRENT, path); std::wstring pathtowrite(path, path+ wcslen(path)); pathtowrite += L"\\LeagueOfChampionCraft"; CreateDirectory(pathtowrite.c_str(), 0); std::wostringstream woss; woss << "\\saveslot" << nSlot << ".xml"; pathtowrite += woss.str(); std::string stringpath(pathtowrite.begin(), pathtowrite.end()); TiXmlDocument doc; if (doc.LoadFile(stringpath.c_str())) { TiXmlElement* pRoot = doc.RootElement(); if (pRoot == nullptr) return; int nMapID, nCurrPlayer, nPhaseCount, nCurrPhase; pRoot->QueryIntAttribute("mapID", &nMapID); pRoot->QueryIntAttribute("currPlayer", &nCurrPlayer); pRoot->QueryIntAttribute("phaseNumber", &nPhaseCount); pRoot->QueryIntAttribute("phase", &nCurrPhase); LoadMap(nMapID); // Map modifcations! Weeeeeeeee int nNumMapModifications; TiXmlElement* pMapMods = pRoot->FirstChildElement("MapModifications"); pMapMods->QueryIntAttribute("numModifications", &nNumMapModifications); TiXmlElement* pMapModification = pMapMods->FirstChildElement("MapModification"); for (int i = 0; i < nNumMapModifications; ++i) { MapModification mod; int nType; pMapModification->QueryIntAttribute("modType", &nType); mod.modType = (SPELL_TYPE)nType; pMapModification->QueryIntAttribute("modPosX", &mod.posX); pMapModification->QueryIntAttribute("modPosY", &mod.posY); pMapModification->QueryIntAttribute("modOtherData", &mod.otherData); switch (mod.modType) { case SP_FAKEMAPMOD: { CTile* selectedTile = CTileManager::GetInstance()->GetTile(mod.posX, mod.posY); if (selectedTile != nullptr) { selectedTile->SetPlayerID(mod.otherData); selectedTile->SetIfCaptured(true); } } break; case SP_RAISEMOUNTAIN: { CTile* selectedTile = CTileManager::GetInstance()->GetTile(mod.posX, mod.posY); if( selectedTile != nullptr ) { if (selectedTile->GetTileType() != TT_FARM && selectedTile->GetTileType() != TT_MILL && selectedTile->GetTileType() != TT_MINE) { selectedTile->SetTileType(TT_MOUNTAINS); selectedTile->SetIfImpassable(false); CGameManager::GetInstance()->AddModification(mod); } } } break; case SP_DESTROYFOREST: { CTile* selectedTile = CTileManager::GetInstance()->GetTile(mod.posX, mod.posY); if( selectedTile != nullptr ) { if (selectedTile->GetTileType() == TT_FOREST) { selectedTile->SetTileType(TT_PLAINS); CGameManager::GetInstance()->AddModification(mod); } } } break; case SP_ICEAGE: { CTile* selectedTile = CTileManager::GetInstance()->GetTile(mod.posX, mod.posY); if( selectedTile != nullptr ) { selectedTile->SetIfFrozen(true); CGameManager::GetInstance()->AddModification(mod); } } break; } pMapModification = pMapModification->NextSiblingElement("MapModification"); } TiXmlElement* pPlayers = pRoot->FirstChildElement("Players"); TiXmlElement* pPlayer = pPlayers->FirstChildElement("Player"); for (decltype(m_vPlayers.size()) i = 0; i < m_vPlayers.size(); ++i) { delete m_vPlayers[i]; } m_vPlayers.clear(); m_nNewPlayerID = 0; for (int np = 0; np < 2; ++np) { int nAIControlled; int nPlayerID; int nAP, nWood, nMetal; pPlayer->QueryIntAttribute("id", &nPlayerID); pPlayer->QueryIntAttribute("ai", &nAIControlled); pPlayer->QueryIntAttribute("wood", &nWood); pPlayer->QueryIntAttribute("AP", &nAP); pPlayer->QueryIntAttribute("metal", &nMetal); CPlayer* pplay = CreatePlayer(IntToBool(nAIControlled)); pplay->SetWood(nWood); pplay->SetAP(nAP); pplay->SetMetal(nMetal); // Load stats! TiXmlElement* pStats = pPlayer->FirstChildElement("Stats"); TiXmlElement* pStat = pStats->FirstChildElement("ChampionDamageDone"); pStat->QueryIntAttribute("value", &pplay->GetStats()->nChampionDamageDone); pStat = pStats->FirstChildElement("ChampionHealingDone"); pStat->QueryIntAttribute("value", &pplay->GetStats()->nChampionHealingDone); pStat = pStats->FirstChildElement("SwordsmanCreated"); pStat->QueryIntAttribute("value", &pplay->GetStats()->nSwordsmanCreated); pStat = pStats->FirstChildElement("ArcherCreated"); pStat->QueryIntAttribute("value", &pplay->GetStats()->nArcherCreated); pStat = pStats->FirstChildElement("CalvaryCreated"); pStat->QueryIntAttribute("value", &pplay->GetStats()->nCalvaryCreated); pStat = pStats->FirstChildElement("SwordsmanDamageDone"); pStat->QueryIntAttribute("value", &pplay->GetStats()->nSwordsmanDamageDone); pStat = pStats->FirstChildElement("ArcherDamageDone"); pStat->QueryIntAttribute("value", &pplay->GetStats()->nArcherDamageDone); pStat = pStats->FirstChildElement("CalvaryDamageDone"); pStat->QueryIntAttribute("value", &pplay->GetStats()->nCalvaryDamageDone); pStat = pStats->FirstChildElement("SwordsmanKilled"); pStat->QueryIntAttribute("value", &pplay->GetStats()->nSwordsmanKilled); pStat = pStats->FirstChildElement("ArcherKilled"); pStat->QueryIntAttribute("value", &pplay->GetStats()->nArcherKilled); pStat = pStats->FirstChildElement("CalvaryKilled"); pStat->QueryIntAttribute("value", &pplay->GetStats()->nCavalryKilled); pStat = pStats->FirstChildElement("WoodEarned"); pStat->QueryIntAttribute("value", &pplay->GetStats()->nPlayerWoodEarned); pStat = pStats->FirstChildElement("WoodSpent"); pStat->QueryIntAttribute("value", &pplay->GetStats()->nPlayerWoodSpent); pStat = pStats->FirstChildElement("MetalEarned"); pStat->QueryIntAttribute("value", &pplay->GetStats()->nPlayerMetalEarned); pStat = pStats->FirstChildElement("MetalSpent"); pStat->QueryIntAttribute("value", &pplay->GetStats()->nPlayerMetalSpent); pStat = pStats->FirstChildElement("APSpent"); pStat->QueryIntAttribute("value", &pplay->GetStats()->nPlayerAPSpent); TiXmlElement* pChampion = pPlayer->FirstChildElement("Champion"); int nPosX, nPosY, nHealth, nXP, nFacing, nTilesMoved, nHasAttacked; // TODO: load in spells here from ability manager pChampion->QueryIntAttribute("posX", &nPosX); pChampion->QueryIntAttribute("posY", &nPosY); pChampion->QueryIntAttribute("health", &nHealth); pChampion->QueryIntAttribute("xp", &nXP); pChampion->QueryIntAttribute("facing", &nFacing); pChampion->QueryIntAttribute("tilesMoved", &nTilesMoved); pChampion->QueryIntAttribute("hasAttacked", &nHasAttacked); pplay->SetExp(nXP); int nNumSpells; TiXmlElement* pSpells = pChampion->FirstChildElement("Spells"); pSpells->QueryIntAttribute("numSpells", &nNumSpells); std::vector< std::pair<SPELL_TYPE, int> > spells; TiXmlElement* pSpell = pSpells->FirstChildElement("Spell"); for (int i = 0; i < nNumSpells; ++i) { int nType; int cooldown; pSpell->QueryIntAttribute("sType", &nType); pSpell->QueryIntAttribute("Cooldown", &cooldown); std::pair<SPELL_TYPE, int> tmp((SPELL_TYPE)nType, cooldown); spells.push_back(tmp); pSpell = pSpell->NextSiblingElement("Spell"); } int nNumBought; TiXmlElement* pBoughtSpells = pChampion->FirstChildElement("BoughtSpells"); pBoughtSpells->QueryIntAttribute("numBought", &nNumBought); std::vector<SPELL_TYPE> bought; TiXmlElement* pBought = pBoughtSpells->FirstChildElement("Bought"); for( int i = 0; i < nNumBought; i++) { int type; pBought->QueryIntAttribute("Type", &type); bought.push_back((SPELL_TYPE)type); pBought = pBought->NextSiblingElement("Bought"); } int nNumEffects; TiXmlElement* pEffects = pChampion->FirstChildElement("Effects"); pEffects->QueryIntAttribute("numEffects", &nNumEffects); std::vector<SPELL_TYPE> effects; TiXmlElement* pEffect = pEffects->FirstChildElement("Effect"); for (int i = 0; i < nNumEffects; ++i) { int nType; pEffect->QueryIntAttribute("ability", &nType); effects.push_back((SPELL_TYPE)nType); pEffect = pEffect->NextSiblingElement("Effect"); } CSpawnUnitMessage* pMsg = new CSpawnUnitMessage(spells, effects, bought, Vec2D(nPosX, nPosY), nPlayerID, UT_HERO, nFacing, true, nHealth, nTilesMoved, IntToBool(nHasAttacked)); CMessageSystem::GetInstance()->SendMessageW(pMsg); int nNumUnits; TiXmlElement* pUnits = pPlayer->FirstChildElement("Units"); pUnits->QueryIntAttribute("numUnits", &nNumUnits); TiXmlElement* pUnit = pUnits->FirstChildElement("Unit"); for (int i = 0; i < nNumUnits; ++i) { int nUnitPosX, nUnitPosY, nUnitType, nUnitHealth, nUnitFacing, nUnitTilesMoved, nUnitHasAttacked; pUnit->QueryIntAttribute("posX", &nUnitPosX); pUnit->QueryIntAttribute("posY", &nUnitPosY); pUnit->QueryIntAttribute("unitType", &nUnitType); pUnit->QueryIntAttribute("health", &nUnitHealth); pUnit->QueryIntAttribute("facing", &nUnitFacing); pUnit->QueryIntAttribute("tilesMoved", &nUnitTilesMoved); pUnit->QueryIntAttribute("hasAttacked", &nUnitHasAttacked); std::vector<std::pair<SPELL_TYPE, int>> spells; int nNumEffects; TiXmlElement* pEffects = pUnit->FirstChildElement("Effects"); pEffects->QueryIntAttribute("numEffects", &nNumEffects); std::vector<SPELL_TYPE> effects; TiXmlElement* pEffect = pEffects->FirstChildElement("Effect"); for (int i = 0; i < nNumEffects; ++i) { int nType; pEffect->QueryIntAttribute("ability", &nType); effects.push_back((SPELL_TYPE)nType); pEffect = pEffect->NextSiblingElement("Effect"); } CSpawnUnitMessage* pUnitMsg = new CSpawnUnitMessage(spells, effects, Vec2D(nUnitPosX, nUnitPosY), nPlayerID, (UNIT_TYPE)nUnitType, nUnitFacing, true, nUnitHealth, nUnitTilesMoved,IntToBool(nUnitHasAttacked) ); CMessageSystem::GetInstance()->SendMessageW(pUnitMsg); pUnit = pUnit->NextSiblingElement("Unit"); } pPlayer = pPlayer->NextSiblingElement("Player"); } SetCurrentPlayer(nCurrPlayer); if (nCurrPlayer == 0) SetNextPlayer(1); else SetNextPlayer(0); SetPhaseCount(nPhaseCount); SetCurrentPhase((GAME_PHASE)nCurrPhase); CMessageSystem::GetInstance()->ProcessMessages(); m_bLoadingFromSave = true; } }
int CMapFileIO::LoadMap(CLevelMap &map) const { return LoadMap(map, m_fname); }
Mesh* Load3ds(string URL, Entity* parent_ent){ int Size; //Local OldDir:String unsigned char Red, Green, Blue; //unsigned char Percent; //Local Pixmap:TPixmap Stream = File::ReadResourceFile(URL); if (Stream == 0) return 0; //Size = Stream.Size() fseek(Stream->pFile, 0, SEEK_END); // seek to end of file Size = ftell(Stream->pFile); // get current file pointer fseek(Stream->pFile, 0, SEEK_SET); // Read Main-Chunk ReadChunk(); if (ChunkID != M3D_3DS_MAIN || ChunkSize != Size) { Stream->CloseFile(); //Print "No 3DS File" return 0; } // Find 3DEditor-Chunk while (Stream->Eof()==0){ ReadChunk(); if (ChunkID == M3D_3DS_3DEDITOR){ break; }else{ SkipChunk(); } } //OldDir = CurrentDir() //If String(URL) <> "" Then ChangeDir(ExtractDir(String(URL))) mesh = Mesh::CreateMesh(); while (Stream->Eof()==0){ ReadChunk(); switch (ChunkID){ case M3D_3DS_OBJECTBLOCK: ReadCString(); // ' ObjectName break; case M3D_3DS_BrushBLOCK: ReadBrushBlock(); break; case M3D_3DS_TRIMESH: ReadTriMesh(); break; case M3D_3DS_VERTEXLIST: ReadVertexList(); break; case M3D_3DS_FACELIST: ReadFaceList(); break; case M3D_3DS_FACEMATLIST: ReadFaceMatList(); break; case M3D_3DS_TEXCOORDS: ReadTexCoords(); break; case M3D_3DS_BrushNAME: //Loader.Brush = CreateBrush() brush->name = ReadCString(); break; case M3D_3DS_BrushAMBIENT: //ReadChunk(); //ReadRGB(ChunkID, Red, Green, Blue); //brush->SetAmbientColor(Red, Green, Blue); break; case M3D_3DS_BrushDIFFUSE: ReadChunk(); ReadRGB(ChunkID, Red, Green, Blue); //brush->BrushColor(Red, Green, Blue); break; case M3D_3DS_BrushSPECULAR: //'Loader.ReadChunk() //'Loader.ReadRGB(Loader.ChunkID, Red, Green, Blue) //'Loader.Brush.SetSpecularColor(Red, Green, Blue) break; case M3D_3DS_BrushSHININESS: //'Loader.ReadChunk() //'Percent = Loader.ReadPercent(Loader.ChunkID) //'Loader.Brush.BrushShininess(Percent) break; case M3D_3DS_MAPFILENAME: LoadMap(); if(brush->no_texs==0) brush->BrushColor(Red, Green, Blue); // only use rgb if no texture break; case M3D_3DS_MAPVSCALE: texture->v_scale = Stream->ReadFloat(); break; case M3D_3DS_MAPUSCALE: texture->u_scale = Stream->ReadFloat(); break; case M3D_3DS_MAPUOFFSET: texture->u_pos = Stream->ReadFloat(); break; case M3D_3DS_MAPVOFFSET: texture->v_pos = Stream->ReadFloat(); break; case M3D_3DS_MAPROTATION: texture->angle = Stream->ReadFloat(); break; default: if ((ChunkID == M3D_3DS_TEXTUREMAP1) || (ChunkID == M3D_3DS_TEXTUREMAP2)) { ReadMap(ChunkID); }else{ SkipChunk(); } } } Stream->CloseFile(); if (surface!=0){ MovedTris.sort(); int CheckSurface=0; for(list<int>::const_reverse_iterator it = MovedTris.rbegin(); it != MovedTris.rend(); it++){ surface->RemoveTri(*it); CheckSurface=1; } MovedTris.clear(); if (surface->no_tris==0 && CheckSurface !=0) { delete surface; mesh->surf_list.remove(surface); mesh->no_surfs=mesh->no_surfs-1; } } // ChangeDir(OldDir) // Loader.Surface.UpdateVertices() // Loader.Surface.UpdateTriangles() mesh->UpdateNormals(); /*Loader.Mesh.UpdateBuffer() Print Loader.Surface.Tris.Length Print Loader.Surface.no_verts 'Loader.Mesh.FlipMesh()*/ mesh->class_name="Mesh"; mesh->AddParent(parent_ent); Entity::entity_list.push_back(mesh); if(mesh->parent!=0){ mesh->mat.Overwrite(mesh->parent->mat); mesh->UpdateMat(); }else{ mesh->UpdateMat(true); } return mesh; }