Weapon::Weapon(const char* wname) { char *pname= 0; char *whname= 0; //char *faname= 0; //char *faimage= 0; map<string, Projectile*>::iterator projentry; map<string, Warhead*>::iterator wheadentry; INIFile * weapini; //SHPImage * fireanimtemp; //Uint8 additional; //Uint8 i; string projname, warheadname; string weapname; INIFile* rules = 0; name = string(wname); rules = new INIFile("rules.ini"); weapini = p::weappool->getWeaponsINI(); weapname = (string)wname; // UPPER the string 'weapname' for_each(weapname.begin(), weapname.end(), toupper); pname = weapini->readString(wname, "projectile"); if (pname == NULL) { logger->warning( "Unable to find projectile for weapon \"%s\" in inifile..\n", wname); throw 0; } projname = (string)pname; // UPPER the string 'projname' for_each(projname.begin(), projname.end(), toupper); projentry = p::weappool->projectilepool.find(projname); if (projentry == p::weappool->projectilepool.end() ) { try { projectile = new Projectile(string(pname), p::raLoader->lnkProjectileDataList, pc::imagepool); } catch(...) { logger->warning("Unable to find projectile \"%s\" used for weapon \"%s\".\nUnit using this weapon will be unarmed\n", pname, wname); delete[] pname; throw 0; } p::weappool->projectilepool[projname] = projectile; } else { projectile = projentry->second; } delete[] pname; whname = weapini->readString(wname, "warhead"); if (whname==NULL) { logger->warning( "Unable to find warhead for weapon \"%s\" in inifile..\n", wname); throw 0; } warheadname = (string)whname; transform(warheadname.begin(), warheadname.end(), warheadname.begin(), toupper); wheadentry = p::weappool->warheadpool.find(warheadname); if (wheadentry == p::weappool->warheadpool.end() ) { try { // Try to create the Warhead whead = new Warhead(whname, p::raLoader->lnkWarheadDataList); } catch(...) { logger->warning("Unable to find Warhead \"%s\" used for weapon \"%s\".\nUnit using this weapon will be unarmed\n", whname, wname); delete[] whname; throw 0; } p::weappool->warheadpool[warheadname] = whead; } else { whead = wheadentry->second; } delete[] whname; speed = weapini->readInt(wname, "speed", 100); range = weapini->readInt(wname, "range", 4); reloadtime = weapini->readInt(wname, "reloadtime", 50); damage = weapini->readInt(wname, "damage", 10); burst = weapini->readInt(wname, "burst", 1); heatseek = (weapini->readInt(wname, "heatseek", 0) != 0); // pc::imagepool->push_back(new SHPImage("minigun.shp", mapscaleq)); //firesound = weapini->readString(wname, "firesound"); //printf("wname = %s\n", wname); report = rules->readString(wname, "Report"); if (report != 0){ string soundWeap = report; soundWeap += string(".aud"); transform(soundWeap.begin(), soundWeap.begin(), soundWeap.end(), tolower); //logger->debug("Report = %s\n", soundWeap.c_str()); report = cppstrdup(soundWeap.c_str()); pc::sfxeng->LoadSound(report); } reloadsound = weapini->readString(wname, "reloadsound"); if (reloadsound != 0) pc::sfxeng->LoadSound(reloadsound); chargingsound = weapini->readString(wname, "chargingsound"); if (chargingsound != 0) pc::sfxeng->LoadSound(chargingsound); fuel = weapini->readInt(wname, "fuel", 0); seekfuel = weapini->readInt(wname, "seekfuel", 0); // @todo Implemente Anim in [Weapon] /* fireimage = pc::imagepool->size()<<16; faname = weapini->readString(wname, "fireimage", "none"); //printf ("%s line %i: Weapon = %s, fireimage = %s\n", __FILE__, __LINE__, wname, faname); if (strcmp((faname), ("none")) == 0) { delete[] faname; numfireimages = 0; numfiredirections = 1; fireimage = 0; } else { additional = (Uint8)weapini->readInt(faname, "additional", 0); faimage = weapini->readString(faname, "image", "minigun.shp"); try { fireanimtemp = new SHPImage(faimage, -1); } catch (ImageNotFound&) { throw 0; } delete[] faimage; faimage = NULL; numfireimages = fireanimtemp->getNumImg(); numfiredirections = weapini->readInt(faname, "directions", 1); if (numfiredirections == 0) { numfiredirections = 1; } fireimages = new Uint32[numfiredirections]; fireimages[0] = fireimage; pc::imagepool->push_back(fireanimtemp); if (additional != 0) { char* tmpname = new char[12]; for (i=2; i<=additional; ++i) { sprintf(tmpname, "image%i", i); faimage = weapini->readString(faname, tmpname, ""); if (strcmp((faimage), ("")) != 0) { try { fireanimtemp = new SHPImage(faimage, -1); } catch (ImageNotFound&) { throw 0; } fireimages[i-1]=(pc::imagepool->size()<<16); numfireimages += fireanimtemp->getNumImg(); pc::imagepool->push_back(fireanimtemp); } else { fireimages[i] = 0; logger->warning("%s was empty in [%s]\n", tmpname, faname); } delete[] faimage; faimage = NULL; } delete[] tmpname; } else if (numfiredirections != 1) { for (i=1; i<numfiredirections; ++i) { fireimages[i] = fireimage+i*(numfireimages/numfiredirections); } } delete[] faname; }*/ // Free rules.ini delete rules; }
/** Constructor, loads the map, sidebar and such. plays briefing and actionmovie */ Game::Game() { ConfigType config; VQAMovie *mov; char* message,*tmp; INIFile* fileini; LoadingScreen *loadscreen; config = getConfig(); /* set the pointer to the gfx engine */ // We let the runtime_error propagate upwards. fileini = new INIFile("files.ini"); asprintf(&tmp,"play%i",config.gamenum); message = fileini->readString("general",tmp,"TD"); free(tmp); if (!pc::sfxeng->createPlayList(message)) { logger->error("Could not create playlist!\n"); throw GameError(); } delete[] message; delete fileini; loadscreen = new LoadingScreen(); gamemode = config.gamemode; if (gamemode == 2) { try { NetConnection::initMessages(); } catch(int) { throw GameError(); } tmp = new char[64]; sprintf(tmp,"Connecting to server: %s",config.serveraddr.c_str()); loadscreen->setCurrentTask(tmp); delete[] tmp; try { pc::conn = new NetConnection(config.serveraddr.c_str(), config.serverport); } catch(int) { delete loadscreen; throw GameError(); } // after connection sending login data loadscreen->setCurrentTask("Sending Login Data"); pc::conn->login(VERSION, config.nick.c_str(), config.mside.c_str(), config.side_colour.c_str()); } /* reset the tickcounter, should be a function in the class conatining the * counter */ loadscreen->setCurrentTask("Creating the ActionEventQueue"); p::aequeue = new ActionEventQueue(); /* load the map */ loadscreen->setCurrentTask("Loading the map."); try { p::ccmap = new CnCMap(); p::ccmap->loadMap(config.mapname.c_str(), loadscreen); } catch (CnCMap::LoadMapError&) { delete loadscreen; // loadmap will have printed the error throw GameError(); } p::dispatcher = new Dispatcher(); switch (config.dispatch_mode) { case 0: break; case 1: // Record break; case 2: // Playback break; default: logger->error("Invalid dispatch mode: %i\n",config.dispatch_mode); throw GameError(); break; } ps::aiplugman = new AI::AIPlugMan(getBinaryLocation()); delete loadscreen; switch (gamemode) { case 0: /* play briefing */ try { mov = new VQAMovie(p::ccmap->getMissionData().brief); mov->play(); delete mov; } catch (VQAError&) { } try { mov = new VQAMovie(p::ccmap->getMissionData().action); mov->play(); delete mov; } catch (VQAError&) { } break; case 1: p::ppool->setupAIs(); break; case 2: break; default: break; } /* init sidebar */ try { pc::sidebar = new Sidebar(p::ppool->getLPlayer(), pc::gfxeng->getHeight(), p::ccmap->getMissionData().theater); } catch (Sidebar::SidebarError&) { throw GameError(); } /* init cursor */ pc::cursor = new Cursor(); /* init the input functions */ pc::input = new Input(pc::gfxeng->getWidth(), pc::gfxeng->getHeight(), pc::gfxeng->getMapArea()); }
Weapon::Weapon(const char* wname) : name(wname) { char *pname, *whname, *faname, *faimage; map<string, Projectile*>::iterator projentry; map<string, Warhead*>::iterator wheadentry; INIFile *weapini = p::weappool->getWeaponsINI(); SHPImage* fireanimtemp; Uint8 additional, i; string projname, warheadname; string weapname = (string)wname; string::iterator p = weapname.begin(); while (p!=weapname.end()) *p++ = toupper(*p); pname = weapini->readString(wname, "projectile"); if( pname == NULL ) { logger->warning("Unable to find projectile for weapon \"%s\" in inifile..\n", wname); throw 0; } projname = (string)pname; p = projname.begin(); while (p!=projname.end()) *p++ = toupper(*p); projentry = p::weappool->projectilepool.find(projname); if( projentry == p::weappool->projectilepool.end() ) { try { projectile = new Projectile(pname, weapini); } catch(int) { logger->warning("Unable to find projectile \"%s\" used for weapon \"%s\".\nUnit using this weapon will be unarmed\n", pname, wname); delete[] pname; throw 0; } p::weappool->projectilepool[projname] = projectile; } else { projectile = projentry->second; } delete[] pname; whname = weapini->readString(wname, "warhead"); if( whname == NULL ) { logger->warning("Unable to find warhead for weapon \"%s\" in inifile..\n", wname); throw 0; } warheadname = (string)whname; transform(warheadname.begin(),warheadname.end(), warheadname.begin(), toupper); wheadentry = p::weappool->warheadpool.find(warheadname); if( wheadentry == p::weappool->warheadpool.end() ) { try { whead = new Warhead(whname, weapini); } catch (int) { logger->warning("Unable to find Warhead \"%s\" used for weapon \"%s\".\nUnit using this weapon will be unarmed\n", whname, wname); delete[] whname; throw 0; } p::weappool->warheadpool[warheadname] = whead; } else { whead = wheadentry->second; } delete[] whname; speed = weapini->readInt(wname, "speed", 100); range = weapini->readInt(wname, "range", 1); reloadtime = weapini->readInt(wname, "reloadtime", 5); damage = weapini->readInt(wname, "damage", 10); burst = weapini->readInt(wname, "burst", 1); heatseek = (weapini->readInt(wname, "heatseek", 0) != 0); fireimage = pc::imagepool->size()<<16; // pc::imagepool->push_back(new SHPImage("minigun.shp", mapscaleq)); firesound = weapini->readString(wname, "firesound"); chargesound = weapini->readString(wname, "chargesound"); fuel = weapini->readInt(wname, "fuel", 0); seekfuel = weapini->readInt(wname, "seekfuel", 0); faname = weapini->readString(wname, "fireimage", "none"); if (strcasecmp(faname,"none") == 0) { delete[] faname; numfireimages = 0; numfiredirections = 1; fireimage = 0; } else { additional = (Uint8)weapini->readInt(faname,"additional",0); faimage = weapini->readString(faname, "image", "minigun.shp"); try { fireanimtemp = new SHPImage(faimage, mapscaleq); } catch (ImageNotFound&) { throw 0; } delete[] faimage; faimage = NULL; numfireimages = fireanimtemp->getNumImg(); numfiredirections = weapini->readInt(faname, "directions", 1); if (numfiredirections == 0) { numfiredirections = 1; } fireimages = new Uint32[numfiredirections]; fireimages[0] = fireimage; pc::imagepool->push_back(fireanimtemp); if (additional != 0) { char* tmpname = new char[12]; for (i=2;i<=additional;++i) { sprintf(tmpname,"image%i",i); faimage = weapini->readString(faname, tmpname, ""); if (strcasecmp(faimage,"") != 0) { try { fireanimtemp = new SHPImage(faimage, mapscaleq); } catch (ImageNotFound&) { throw 0; } fireimages[i-1]=(pc::imagepool->size()<<16); numfireimages += fireanimtemp->getNumImg(); pc::imagepool->push_back(fireanimtemp); } else { fireimages[i] = 0; logger->warning("%s was empty in [%s]\n",tmpname,faname); } delete[] faimage; faimage = NULL; } delete[] tmpname; } else if (numfiredirections != 1) { for (i=1;i<numfiredirections;++i) { fireimages[i] = fireimage+i*(numfireimages/numfiredirections); } } delete[] faname; } }
/** * GraphicsEngine, SoundEngine, VFSUtils file system, ImageCache and imagepool, RADataLoader and ConfigType object from ini file (externals) */ void Game::InitializeGameClasses() { /// Initialise the Graphics Engine try { logger->note("Initialising the graphics engine..."); pc::gfxeng = new GraphicsEngine(); logger->note("done\n"); } catch (VideoError& ex) { logger->note("failed. %s \n", ex.what()); throw runtime_error("Unable to initialise the graphics engine"); } /// Initialise Sound try { logger->note("Initialising the sound engine..."); pc::sfxeng = new SoundEngine(pc::Config.nosound); logger->note("done\n"); } catch (SoundError& error) { logger->error("%s\n", error.what()); logger->note("failed. exiting\n"); throw runtime_error("Unable to initialise the sound engine"); } /// Initialise the VFS file system VFSUtils::VFS_PreInit(pc::Config.binpath.c_str()); VFSUtils::VFS_Init(pc::Config.binpath.c_str()); VFSUtils::VFS_LoadGame(pc::Config.gamenum); // Get the mission maps //pc::MissionsMapdata = new MissionMapsClass(); // Init the image cache pc::imagepool = new std::vector<SHPImage*>(); pc::imgcache->setImagePool(pc::imagepool); //pc::imgcache->setImagePool(new std::vector<SHPImage*>()); /// Init the Data Loader try { logger->note("Initialising the RA Data loader..."); p::raLoader = new RedAlertDataLoader(); p::raLoader->load(); logger->note("done\n"); } catch (...) { logger->note("failed. exiting\n"); throw runtime_error("Unable to initialise the RA Data loader"); } // Load the music files (for background music // Create playlist with all music of RedAlert if (pc::sfxeng->CreatePlaylist() != true) { // logger->error("Could not create playlist!\n"); // throw GameError("Could not create playlist!\n"); } // Load the sounds ini file INIFile *soundini = GetConfig("sound.ini"); /// Structures pc::Config.StructureDestroyed = soundini->readString("STRUCTURES", "destroyed", "kaboom22.aud"); pc::Config.StructureHalfDestroyed = soundini->readString("STRUCTURES", "halfdestroyed", "kaboom1.aud"); pc::Config.StructureSold = soundini->readString("STRUCTURES", "sold", "strusld1.aud"); pc::Config.StructurePlaced = soundini->readString("STRUCTURES", "placed", "build5.aud"); pc::Config.RepairStructure = soundini->readString("STRUCTURES", "repair", "repair1.aud"); pc::Config.PrimairyStructureSelected = soundini->readString("STRUCTURES", "primairy", "pribldg1.aud"); pc::Config.StructureStartBuild = soundini->readString("STRUCTURES", "startbuilding", "abldgin1.aud"); pc::Config.StructureReady = soundini->readString("STRUCTURES", "constrcomplete", "conscmp1.aud"); /// Units pc::Config.UnitFull = soundini->readString("UNITS", "full", "unitful1.aud"); pc::Config.UnitLost = soundini->readString("UNITS", "lost", "unitlst1.aud"); pc::Config.RepairUnit = soundini->readString("UNITS", "repair", "repair1.aud"); pc::Config.UnitRepaired = soundini->readString("UNITS", "repaired", "unitrep1.aud"); pc::Config.UnitSold = soundini->readString("UNITS", "sold", "unitsld1.aud"); pc::Config.UnitReady = soundini->readString("UNITS", "ready", "unitrdy1.aud"); pc::Config.UnitDeployed = soundini->readString("UNITS", "deployed", "build5.aud"); pc::Config.AirUnitLost = soundini->readString("UNITS", "airunitlost", "aunitl1.aud"); pc::Config.TrainUnit = soundini->readString("UNITS", "starttraining", "train1.aud"); /// Base pc::Config.BaseUnderAttack = soundini->readString("BASE", "underattack", "baseatk1.aud"); pc::Config.CmdCentreUnderAttack = soundini->readString("BASE", "centerunderattack", "cmdcntr1.aud"); /// Naval pc::Config.NavalUnitLost = soundini->readString("NAVAL", "unitlost", "navylst1.aud"); /// General pc::Config.BattleControlTerm = soundini->readString("GENERAL", "terminate", "bct1.aud"); pc::Config.BuildingCanceled = soundini->readString("GENERAL", "buildingcanceled", "cancld1.aud"); pc::Config.BuildingOnHold = soundini->readString("GENERAL", "buildingonhold", "onhold1.aud"); pc::Config.Newoptions = soundini->readString("GENERAL", "newoptions", "newopt1.aud"); pc::Config.NoDeploy = soundini->readString("GENERAL", "nodeploy", "nodeply1.aud"); // Has to be use jet pc::Config.NoFunds = soundini->readString("GENERAL", "nomoney", "nofunds1.aud"); // Has to be use jet pc::Config.Nopower = soundini->readString("GENERAL", "nopower", "nopowr1.aud"); // Has to be use jet pc::Config.Reinforcements = soundini->readString("GENERAL", "reinforcements", "reinfor1.aud"); // Has to be use jet pc::Config.RadarUp = soundini->readString("GENERAL", "radarup", "radaron2.aud"); pc::Config.RadarDown = soundini->readString("GENERAL", "radardown", "radardn1.aud"); pc::Config.MissionWon = soundini->readString("GENERAL", "missionwon", "misnwon1.aud"); pc::Config.MissionLost = soundini->readString("GENERAL", "missionlost", "misnlst1.aud"); /// Money pc::Config.MoneyCountUp = soundini->readString("MONEY", "countup", "cashup1.aud"); // Has to be use jet pc::Config.MoneyCountDown = soundini->readString("MONEY", "countdown", "cashdn1.aud"); // Has to be use jet }