void begin_cleartype_fix() // execute this function after loading settings from init.txt, but before the user is actively playing the game
{
   if(fixcleartype) // only do anything if fixcleartype was set in init.txt and we're running Windows XP or later
	{
      // first we get the font smoothing parameters from Windows so that the old settings are backed up
      SystemParametersInfo(SPI_GETFONTSMOOTHING, 0, &FontSmoothingEnabled, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);
      SystemParametersInfo(SPI_GETFONTSMOOTHINGTYPE, 0, &TypeOfFontSmoothing, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);
      // now we see if the game crashed or exited prematurely the last time, and load the font smoothing parameters from the file if
      //     that is the case, to ensure that the user's original font smoothing settings will be restored when they exit the game
      FILE *h;
      h=LCSOpenFile("cleartype.dat", "rb", LCSIO_PRE_HOME);
      if(h!=NULL)
      {
         fread(&FontSmoothingEnabled,sizeof(BOOL),1,h);
         fread(&TypeOfFontSmoothing,sizeof(UINT),1,h);
         LCSCloseFile(h);
      }
      // now that we know for sure what the original settings were, and both the variables FontSmoothingEnabled and
      // TypeOfFontSmoothing are guaranteed to be the original settings prior to any modifications by this game, we can
      // back the original settings up to disk, in case the game crashes or is exited prematurely
      h=LCSOpenFile("cleartype.dat", "wb", LCSIO_PRE_HOME);
      if(h!=NULL)
      {
         fwrite(&FontSmoothingEnabled,sizeof(BOOL),1,h);
         fwrite(&TypeOfFontSmoothing,sizeof(UINT),1,h);
         LCSCloseFile(h);
         // now that everything is safely backed up, we set the font smoothing parameters to be optimal for Liberal Crime Squad
         // ClearType messes things up and causes visual artifacts in Win32 Console Apps like this game so it's going to be off
         // but we'll have standard font smoothing on because it looks really good with Lucida Console, and doesn't affect raster fonts at all
         SystemParametersInfo(SPI_SETFONTSMOOTHING, TRUE, 0, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);
         SystemParametersInfo(SPI_SETFONTSMOOTHINGTYPE, 0, (void*)FE_FONTSMOOTHINGSTANDARD, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);
      }
	}
}
Exemple #2
0
/* loads the high scores file */
void loadhighscores()
{
   for(int s=0;s<SCORENUM;s++)score[s].valid=0;

   //LOAD FILE
   int loadversion;

   FILE *h=LCSOpenFile("score.dat", "rb", LCSIO_PRE_HOME);
   if(h!=NULL)
   {
      fread(&loadversion,sizeof(int),1,h);

      if(loadversion<lowestloadscoreversion)
      {
         LCSCloseFile(h);
         return;
      }

      fread(&ustat_recruits,sizeof(int),1,h);
      fread(&ustat_dead,sizeof(int),1,h);
      fread(&ustat_kills,sizeof(int),1,h);
      fread(&ustat_kidnappings,sizeof(int),1,h);
      fread(&ustat_funds,sizeof(int),1,h);
      fread(&ustat_spent,sizeof(int),1,h);
      fread(&ustat_buys,sizeof(int),1,h);
      fread(&ustat_burns,sizeof(int),1,h);
      fread(score,sizeof(highscorest),SCORENUM,h);

      LCSCloseFile(h);
   }
}
void savegame(const string& filename)
{
#ifdef NOSAVE
   return;
#endif

   bool dummy_b;
   int dummy;
   FILE *h;
   int l;

   h=LCSOpenFile(filename.c_str(), "wb", LCSIO_PRE_HOME);

   if(h!=NULL)
   {
      int lversion=version;
      fwrite(&lversion,sizeof(int),1,h);

      fwrite(seed,sizeof(unsigned long),RNG_SIZE,h);

      fwrite(&mode,sizeof(short),1,h);
      fwrite(&wincondition,sizeof(short),1,h);
      fwrite(&fieldskillrate,sizeof(short),1,h);

      fwrite(&day,sizeof(int),1,h);
      fwrite(&month,sizeof(int),1,h);
      fwrite(&year,sizeof(int),1,h);
      fwrite(&execterm,sizeof(short),1,h);
      fwrite(&presparty,sizeof(short),1,h);
      fwrite(&amendnum,sizeof(int),1,h);

      fwrite(&multipleCityMode,sizeof(bool),1,h);
      fwrite(&termlimits,sizeof(bool),1,h);
      fwrite(&deagle,sizeof(bool),1,h);
      fwrite(&m249,sizeof(bool),1,h);
      fwrite(&notermlimit,sizeof(bool),1,h);
      fwrite(&nocourtpurge,sizeof(bool),1,h);
      fwrite(&stalinmode,sizeof(bool),1,h);

      fwrite(&stat_recruits,sizeof(int),1,h);
      fwrite(&stat_dead,sizeof(int),1,h);
      fwrite(&stat_kills,sizeof(int),1,h);
      fwrite(&stat_kidnappings,sizeof(int),1,h);
      fwrite(&stat_buys,sizeof(int),1,h);
      fwrite(&stat_burns,sizeof(int),1,h);

      fwrite(&endgamestate,sizeof(char),1,h);
      fwrite(&ccsexposure,sizeof(char),1,h);
      fwrite(&ccs_kills,sizeof(char),1,h);

      fwrite(&Vehicle::curcarid,sizeof(long),1,h);
      fwrite(&curcreatureid,sizeof(long),1,h);
      fwrite(&cursquadid,sizeof(long),1,h);
      fwrite(&police_heat,sizeof(int),1,h);
      fwrite(&offended_corps,sizeof(short),1,h);
      fwrite(&offended_cia,sizeof(short),1,h);
      fwrite(&offended_amradio,sizeof(short),1,h);
      fwrite(&offended_cablenews,sizeof(short),1,h);
      fwrite(&offended_firemen,sizeof(short),1,h);
      fwrite(attorneyseed,sizeof(unsigned long),RNG_SIZE,h);
      //fwrite(&selectedsiege,sizeof(long),1,h);
      fwrite(lcityname,sizeof(char),CITY_NAMELEN,h);
      fwrite(&newscherrybusted,sizeof(char),1,h);

      fwrite(slogan,sizeof(char),SLOGAN_LEN,h);
      fwrite(&ledger,sizeof(class Ledger),1,h);
      fwrite(&party_status,sizeof(short),1,h);

      fwrite(attitude,sizeof(short),VIEWNUM,h);
      fwrite(law,sizeof(short),LAWNUM,h);
      fwrite(house,sizeof(short),HOUSENUM,h);
      fwrite(senate,sizeof(short),SENATENUM,h);
      fwrite(court,sizeof(short),COURTNUM,h);
      fwrite(courtname,sizeof(char)*POLITICIAN_NAMELEN,9,h);
      fwrite(exec,sizeof(char),EXECNUM,h);
      fwrite(execname,sizeof(char)*POLITICIAN_NAMELEN,EXECNUM,h);
      fwrite(oldPresidentName,sizeof(char),POLITICIAN_NAMELEN,h);

      //LOCATIONS
      dummy=len(location);
      fwrite(&dummy,sizeof(int),1,h);
      for(l=0;l<len(location);l++)
      {
         consolidateloot(location[l]->loot); // consolidate loot before saving
         dummy=len(location[l]->loot);
         fwrite(&dummy,sizeof(int),1,h);
         for(int l2=0;l2<len(location[l]->loot);l2++)
         {
            std::string itemStr = location[l]->loot[l2]->showXml();
            int itemSize = len(itemStr);

            fwrite(&itemSize,sizeof(int),1,h);
            fwrite(itemStr.c_str(),itemSize,1,h);
         }
         dummy=len(location[l]->changes);
         fwrite(&dummy,sizeof(int),1,h);
         for(int l2=0;l2<len(location[l]->changes);l2++)
            fwrite(&location[l]->changes[l2],sizeof(sitechangest),1,h);

         fwrite(location[l]->name,sizeof(char),LOCATION_NAMELEN,h);
         fwrite(location[l]->shortname,sizeof(char),LOCATION_SHORTNAMELEN,h);
         fwrite(&location[l]->type,sizeof(char),1,h);
         fwrite(&location[l]->city,sizeof(int),1,h);
         fwrite(&location[l]->area,sizeof(int),1,h);
         fwrite(&location[l]->parent,sizeof(int),1,h);
         fwrite(&location[l]->id,sizeof(int),1,h);

         fwrite(&location[l]->renting,sizeof(int),1,h);
         fwrite(&location[l]->newrental,sizeof(char),1,h);
         fwrite(&location[l]->needcar,sizeof(char),1,h);
         fwrite(&location[l]->closed,sizeof(int),1,h);
         fwrite(&location[l]->hidden,sizeof(bool),1,h);
         fwrite(&location[l]->mapped,sizeof(bool),1,h);
         fwrite(&location[l]->upgradable,sizeof(bool),1,h);
         fwrite(&location[l]->highsecurity,sizeof(int),1,h);
         fwrite(&location[l]->siege,sizeof(siegest),1,h);
         fwrite(&location[l]->heat,sizeof(int),1,h);
         fwrite(&location[l]->heat_protection,sizeof(int),1,h);
         fwrite(&location[l]->compound_walls,sizeof(int),1,h);
         fwrite(&location[l]->compound_stores,sizeof(int),1,h);
         fwrite(&location[l]->front_business,sizeof(char),1,h);
         fwrite(location[l]->front_name,sizeof(char),LOCATION_NAMELEN,h);
         fwrite(location[l]->front_shortname,sizeof(char),LOCATION_SHORTNAMELEN,h);
         fwrite(&location[l]->haveflag,sizeof(bool),1,h);

         fwrite(location[l]->mapseed,sizeof(unsigned long),RNG_SIZE,h);
      }

      //VEHICLES
      dummy=len(vehicle);
      fwrite(&dummy,sizeof(int),1,h);
      for(l=0;l<len(vehicle);l++)
      {
         std::string vehicleStr = vehicle[l]->showXml();
         int vehicleSize = len(vehicleStr);

         fwrite(&vehicleSize,sizeof(int),1,h);
         fwrite(vehicleStr.c_str(),vehicleSize,1,h);
      }

      //POOL
      dummy=len(pool);
      fwrite(&dummy,sizeof(int),1,h);
      for(int pl=0;pl<len(pool);pl++)
      {
         std::string creatureStr = pool[pl]->showXml();
         int creatureSize = len(creatureStr);

         fwrite(&creatureSize,sizeof(int),1,h);
         fwrite(creatureStr.c_str(),creatureSize,1,h);
         //fwrite(pool[pl],sizeof(Creature),1,h);
         //write extra interrogation data if applicable
         if(pool[pl]->align==-1 && pool[pl]->alive)
         {
            interrogation* &intr = pool[pl]->activity.intr();
            fwrite(intr->techniques,sizeof(bool[6]),1,h);
            fwrite(&intr->druguse,sizeof(int),1,h);

            //deep write rapport map
            int size = len(intr->rapport);
            fwrite(&size,sizeof(int),1,h);
            for(map<long,float_zero>::iterator i=intr->rapport.begin();i!=intr->rapport.end();i++)
            {
               fwrite(&i->first,sizeof(long),1,h);
               fwrite(&i->second,sizeof(float_zero),1,h);
            }
         }
      }

      //Unique Creatures
      {
         std::string uniquecreaturesStr = uniqueCreatures.showXml();
         int uniquecreaturesSize = len(uniquecreaturesStr);

         fwrite(&uniquecreaturesSize,sizeof(int),1,h);
         fwrite(uniquecreaturesStr.c_str(),uniquecreaturesSize,1,h);
         //fwrite(&uniqueCreatures,sizeof(UniqueCreatures),1,h);
      }

      //SQUADS
      dummy=len(squad);
      fwrite(&dummy,sizeof(int),1,h);
      for(int sq=0;sq<len(squad);sq++)
      {
         fwrite(squad[sq]->name,sizeof(char),SQUAD_NAMELEN,h);
         fwrite(&squad[sq]->activity,sizeof(activityst),1,h);
         fwrite(&squad[sq]->id,sizeof(int),1,h);

         for(int pos=0;pos<6;pos++)
         {
            dummy_b=squad[sq]->squad[pos];
            fwrite(&dummy_b,sizeof(bool),1,h);
            if(dummy_b)
               fwrite(&squad[sq]->squad[pos]->id,sizeof(int),1,h);
         }

         consolidateloot(squad[sq]->loot); // consolidate loot before saving
         dummy=len(squad[sq]->loot);
         fwrite(&dummy,sizeof(int),1,h);
         for(int l2=0;l2<len(squad[sq]->loot);l2++)
         {
            std::string itemStr = squad[sq]->loot[l2]->showXml();
            int itemSize = len(itemStr);

            fwrite(&itemSize,sizeof(int),1,h);
            fwrite(itemStr.c_str(),itemSize,1,h);
         }
      }

      dummy_b=activesquad;
      fwrite(&dummy_b,sizeof(bool),1,h);
      if(dummy_b)
         fwrite(&activesquad->id,sizeof(int),1,h);

      //DATES
      dummy=len(date);
      fwrite(&dummy,sizeof(int),1,h);
      for(int dt=0;dt<len(date);dt++)
      {
         fwrite(&date[dt]->mac_id,sizeof(long),1,h);
         fwrite(&date[dt]->timeleft,sizeof(short),1,h);
         fwrite(&date[dt]->city,sizeof(int),1,h);

         dummy=len(date[dt]->date);
         fwrite(&dummy,sizeof(int),1,h);
         for(int dt2=0;dt2<len(date[dt]->date);dt2++)
         {
            std::string creatureStr = date[dt]->date[dt2]->showXml();
            int creatureSize = len(creatureStr);

            fwrite(&creatureSize,sizeof(int),1,h);
            fwrite(creatureStr.c_str(),creatureSize,1,h);
            //fwrite(date[dt]->date[dt2],sizeof(Creature),1,h);
         }
      }

      //RECRUITS
      dummy=len(recruit);
      fwrite(&dummy,sizeof(int),1,h);
      for(int rt=0;rt<len(recruit);rt++)
      {
         fwrite(&recruit[rt]->recruiter_id,sizeof(long),1,h);
         fwrite(&recruit[rt]->timeleft,sizeof(short),1,h);
         fwrite(&recruit[rt]->level,sizeof(char),1,h);
         fwrite(&recruit[rt]->eagerness1,sizeof(char),1,h);
         fwrite(&recruit[rt]->task,sizeof(char),1,h);

         std::string creatureStr = recruit[rt]->recruit->showXml();
         int creatureSize = len(creatureStr);

         fwrite(&creatureSize,sizeof(int),1,h);
         fwrite(creatureStr.c_str(),creatureSize,1,h);
         //fwrite(recruit[rt]->recruit,sizeof(Creature),1,h);
      }

      //NEWS STORIES
      dummy=len(newsstory);
      fwrite(&dummy,sizeof(int),1,h);
      for(int ns=0;ns<len(newsstory);ns++)
      {
         fwrite(&newsstory[ns]->type,sizeof(short),1,h);
         fwrite(&newsstory[ns]->view,sizeof(short),1,h);

         fwrite(&newsstory[ns]->loc,sizeof(long),1,h);
         fwrite(&newsstory[ns]->priority,sizeof(long),1,h);
         fwrite(&newsstory[ns]->page,sizeof(long),1,h);
         fwrite(&newsstory[ns]->positive,sizeof(char),1,h);
         fwrite(&newsstory[ns]->siegetype,sizeof(short),1,h);

         dummy_b=newsstory[ns]->cr;
         fwrite(&dummy_b,sizeof(bool),1,h);
         if(dummy_b)
            fwrite(&newsstory[ns]->cr->id,sizeof(long),1,h);

         dummy=len(newsstory[ns]->crime);
         fwrite(&dummy,sizeof(int),1,h);
         for(int dt2=0;dt2<len(newsstory[ns]->crime);dt2++)
            fwrite(&newsstory[ns]->crime[dt2],sizeof(int),1,h);
      }

      // Liberal Media
      fwrite(public_interest,sizeof(public_interest),1,h);
      fwrite(background_liberal_influence,sizeof(background_liberal_influence),1,h);

      // Site mode options
      fwrite(&encounterwarnings,sizeof(bool),1,h);
      bool musicenabled=music.isEnabled();
      fwrite(&musicenabled,sizeof(bool),1,h);

      LCSCloseFile(h);
   }
}
/* loads the game from save.dat */
char load(const string& filename)
{
   //LOAD FILE
   int loadversion;
   int l;
   bool dummy_b;
   int dummy;
   long dummy_l;
   FILE *h;

   h=LCSOpenFile(filename.c_str(), "rb", LCSIO_PRE_HOME);
   if(h!=NULL)
   {
      fread(&loadversion,sizeof(int),1,h);

      //NUKE INVALID SAVE GAMES
      if(loadversion<lowestloadversion)
      {
            LCSCloseFile(h);

            reset();

            return 0;
         }

         fread(seed,sizeof(unsigned long),RNG_SIZE,h);

         fread(&mode,sizeof(short),1,h);
         fread(&wincondition,sizeof(short),1,h);
         fread(&fieldskillrate,sizeof(short),1,h);

         fread(&day,sizeof(int),1,h);
         fread(&month,sizeof(int),1,h);
         fread(&year,sizeof(int),1,h);
         fread(&execterm,sizeof(short),1,h);
         fread(&presparty,sizeof(short),1,h);
         fread(&amendnum,sizeof(int),1,h);

         fread(&multipleCityMode,sizeof(bool),1,h);
         fread(&termlimits,sizeof(bool),1,h);
         fread(&deagle,sizeof(bool),1,h);
         fread(&m249,sizeof(bool),1,h);
         fread(&notermlimit,sizeof(bool),1,h);
         fread(&nocourtpurge,sizeof(bool),1,h);
         fread(&stalinmode,sizeof(bool),1,h);

         fread(&stat_recruits,sizeof(int),1,h);
         fread(&stat_dead,sizeof(int),1,h);
         fread(&stat_kills,sizeof(int),1,h);
         fread(&stat_kidnappings,sizeof(int),1,h);
         fread(&stat_buys,sizeof(int),1,h);
         fread(&stat_burns,sizeof(int),1,h);

         fread(&endgamestate,sizeof(char),1,h);
         fread(&ccsexposure,sizeof(char),1,h);
         fread(&ccs_kills,sizeof(char),1,h);

         fread(&Vehicle::curcarid,sizeof(long),1,h);
         fread(&curcreatureid,sizeof(long),1,h);
         fread(&cursquadid,sizeof(long),1,h);
         fread(&police_heat,sizeof(int),1,h);
         fread(&offended_corps,sizeof(short),1,h);
         fread(&offended_cia,sizeof(short),1,h);
         fread(&offended_amradio,sizeof(short),1,h);
         fread(&offended_cablenews,sizeof(short),1,h);
         fread(&offended_firemen,sizeof(short),1,h);
         fread(attorneyseed,sizeof(unsigned long),RNG_SIZE,h);
         //fread(&selectedsiege,sizeof(long),1,h);
         fread(lcityname,sizeof(char),CITY_NAMELEN,h);
         fread(&newscherrybusted,sizeof(char),1,h);

         fread(slogan,sizeof(char),SLOGAN_LEN,h);
         fread(&ledger,sizeof(class Ledger),1,h);
         fread(&party_status,sizeof(short),1,h);

         fread(attitude,sizeof(short),VIEWNUM,h);
         fread(law,sizeof(short),LAWNUM,h);
         fread(house,sizeof(short),HOUSENUM,h);
         fread(senate,sizeof(short),SENATENUM,h);
         fread(court,sizeof(short),COURTNUM,h);
         fread(courtname,sizeof(char)*POLITICIAN_NAMELEN,COURTNUM,h);
         fread(exec,sizeof(char),EXECNUM,h);
         fread(execname,sizeof(char)*POLITICIAN_NAMELEN,EXECNUM,h);
         fread(oldPresidentName,sizeof(char),POLITICIAN_NAMELEN,h);

         //LOCATIONS
         fread(&dummy,sizeof(int),1,h);
         location.resize(dummy);
         for(l=0;l<len(location);l++)
         {
            location[l]=new Location;

            fread(&dummy,sizeof(int),1,h);
            location[l]->loot.resize(dummy);
            for(int l2=0;l2<len(location[l]->loot);l2++)
            {
               int itemLen;
               fread(&itemLen, sizeof(int), 1, h);
               vector<char> vec = vector<char>(itemLen + 1);
               fread(&vec[0], itemLen, 1, h);
               vec[itemLen] = '\0';

               Item* it = create_item(&vec[0]);
               if(it!=NULL)
                  location[l]->loot[l2] = it;
            }
            //Remove items of unknown type.
            for(int l2=len(location[l]->loot)-1; l2>=0; l2--)
            {
               bool del = false;
               if(location[l]->loot[l2]->is_loot())
                  del = (getloottype(location[l]->loot[l2]->get_itemtypename()) == -1);
               else if(location[l]->loot[l2]->is_clip())
                  del = (getcliptype(location[l]->loot[l2]->get_itemtypename()) == -1);
               else if(location[l]->loot[l2]->is_weapon())
                  del = (getweapontype(location[l]->loot[l2]->get_itemtypename()) == -1);
               else if(location[l]->loot[l2]->is_armor())
                  del = (getarmortype(location[l]->loot[l2]->get_itemtypename()) == -1);

               if(del)
               {
                  addstr("Item type ");
                  addstr(location[l]->loot[l2]->get_itemtypename());
                  addstr(" does not exist. Deleting item.");
                  delete_and_remove(location[l]->loot,l2);
               }
            }
            consolidateloot(location[l]->loot); // consolidate loot after loading

            fread(&dummy,sizeof(int),1,h);
            location[l]->changes.resize(dummy);
            for(int l2=0;l2<len(location[l]->changes);l2++)
               fread(&location[l]->changes[l2],sizeof(sitechangest),1,h);

            fread(location[l]->name,sizeof(char),LOCATION_NAMELEN,h);
            fread(location[l]->shortname,sizeof(char),LOCATION_SHORTNAMELEN,h);
            fread(&location[l]->type,sizeof(char),1,h);
            fread(&location[l]->city,sizeof(int),1,h);
            fread(&location[l]->area,sizeof(int),1,h);
            fread(&location[l]->parent,sizeof(int),1,h);
            fread(&location[l]->id,sizeof(int),1,h);

            fread(&location[l]->renting,sizeof(int),1,h);
            fread(&location[l]->newrental,sizeof(char),1,h);
            fread(&location[l]->needcar,sizeof(char),1,h);
            fread(&location[l]->closed,sizeof(int),1,h);
            fread(&location[l]->hidden,sizeof(bool),1,h);
            fread(&location[l]->mapped,sizeof(bool),1,h);
            fread(&location[l]->upgradable,sizeof(bool),1,h);
            fread(&location[l]->highsecurity,sizeof(int),1,h);
            fread(&location[l]->siege,sizeof(siegest),1,h);
            fread(&location[l]->heat,sizeof(int),1,h);
            fread(&location[l]->heat_protection,sizeof(int),1,h);
            fread(&location[l]->compound_walls,sizeof(int),1,h);
            fread(&location[l]->compound_stores,sizeof(int),1,h);
            fread(&location[l]->front_business,sizeof(char),1,h);
            fread(location[l]->front_name,sizeof(char),LOCATION_NAMELEN,h);
            fread(location[l]->front_shortname,sizeof(char),LOCATION_SHORTNAMELEN,h);
            fread(&location[l]->haveflag,sizeof(bool),1,h);

            fread(location[l]->mapseed,sizeof(unsigned long),RNG_SIZE,h);
         }

         //VEHICLES
         fread(&dummy,sizeof(int),1,h);
         vehicle.resize(dummy);
         for(l=0;l<len(vehicle);l++)
         {
            int vehicleLen;
            fread (&vehicleLen, sizeof(int), 1, h);
            vector<char> vec = vector<char> (vehicleLen + 1);
            fread (&vec[0], vehicleLen, 1, h);
            vec[vehicleLen] = '\0';
            vehicle[l] = new Vehicle (&vec[0]);
         }

         //POOL
         fread(&dummy,sizeof(int),1,h);
         pool.resize(dummy);
         for(int pl=0;pl<len(pool);pl++)
         {
            int creatureLen;
            fread (&creatureLen, sizeof(int), 1, h);
            vector<char> vec = vector<char> (creatureLen + 1);
            fread (&vec[0], creatureLen, 1, h);
            vec[creatureLen] = '\0';
            pool[pl] = new Creature(&vec[0]);
            //pool[pl]=new Creature;
            //fread(pool[pl],sizeof(Creature),1,h);
            //read extra interrogation data if applicable
            if(pool[pl]->align==-1 && pool[pl]->alive)
            {
               interrogation* &intr = pool[pl]->activity.intr();
               intr = new interrogation;
               fread(intr->techniques,sizeof(bool[6]),1,h);
               fread(&intr->druguse,sizeof(int),1,h);

               intr->rapport.clear();
               int size;
               fread(&size,sizeof(int),1,h);
               for(int i=0;i<size;i++)
               {
                  long id;
                  float_zero value;
                  fread(&id,sizeof(long),1,h);
                  fread(&value,sizeof(float_zero),1,h);
                  intr->rapport[id]=value;
               }
            }
            /*
            //read equipment
            vector<Item*> dump; //Used to catch invalid pointers from creature so they aren't deleted.
            pool[pl]->drop_weapon(&dump);
            pool[pl]->strip(&dump);
            pool[pl]->clips = deque<Clip*>();
            pool[pl]->extra_throwing_weapons = deque<Weapon*>();
            int itemLen;
            fread(&itemLen, sizeof(int), 1, h);
            if(itemLen != 0)
            {
               vector<char> vec = vector<char>(itemLen + 1);
               fread(&vec[0], itemLen, 1, h);
               vec[itemLen] = '\0';

               Weapon w(&vec[0]);
               if(getweapontype(w.get_itemtypename())!=-1) //Check it is a valid weapon type.
                  pool[pl]->give_weapon(w,&dump);
            }
            //pool[pl]->clips.clear();
            fread(&dummy,sizeof(int),1,h);
            for(int nc=0; nc<dummy; nc++)
            {
               fread(&itemLen, sizeof(itemLen), 1, h);
               vector<char> vec = vector<char>(itemLen + 1);
               fread(&vec[0], itemLen, 1, h);
               vec[itemLen] = '\0';

               Clip c(&vec[0]);
               if(getcliptype(c.get_itemtypename())!=-1) //Check it is a valid clip type.
                  pool[pl]->take_clips(c,len(c));
            }
            //pool[pl]->extra_throwing_weapons.clear();
            fread(&dummy,sizeof(int),1,h);
            for(int ne=0; ne<dummy; ne++)
            {
               fread(&itemLen, sizeof(itemLen), 1, h);
               vector<char> vec = vector<char>(itemLen + 1);
               fread(&vec[0], itemLen, 1, h);
               vec[itemLen] = '\0';

               Weapon w(&vec[0]);
               if(getweapontype(w.get_itemtypename())!=-1) //Check it is a valid weapon type.
                  pool[pl]->give_weapon(w,NULL);
            }
            fread(&itemLen, sizeof(itemLen), 1, h);
            if(itemLen != 0)
            {
               vector<char> vec = vector<char>(itemLen + 1);
               fread(&vec[0], itemLen, 1, h);
               vec[itemLen] = '\0';

               Armor a(&vec[0]);
               if(getarmortype(a.get_itemtypename())!=-1) //Check it is a valid armor type.
                  pool[pl]->give_armor(a,&dump);
            }*/
         }

         //Unique Creatures
         {
            int uniquecreaturesLen;
            fread (&uniquecreaturesLen, sizeof(int), 1, h);
            vector<char> vec = vector<char> (uniquecreaturesLen + 1);
            fread (&vec[0], uniquecreaturesLen, 1, h);
            vec[uniquecreaturesLen] = '\0';
            uniqueCreatures = UniqueCreatures(&vec[0]);
            //fread(&uniqueCreatures,sizeof(UniqueCreatures),1,h);
         }

         //SQUADS
         fread(&dummy,sizeof(int),1,h);
         squad.resize(dummy);
         for(int sq=0;sq<len(squad);sq++)
         {
            squad[sq]=new squadst;

            fread(squad[sq]->name,sizeof(char),SQUAD_NAMELEN,h);
            fread(&squad[sq]->activity,sizeof(activityst),1,h);
            fread(&squad[sq]->id,sizeof(int),1,h);

            for(int pos=0;pos<6;pos++)
            {
               //REBUILD SQUAD FROM POOL
               squad[sq]->squad[pos]=NULL;
               fread(&dummy_b,sizeof(bool),1,h);
               if(dummy_b)
               {
                  int dummy_i;
                  fread(&dummy_i,sizeof(int),1,h);
                  for(int pl=0;pl<len(pool);pl++)
                     if(pool[pl]->id==dummy_i)
                        squad[sq]->squad[pos]=pool[pl];
               }
            }

            fread(&dummy,sizeof(int),1,h);
            squad[sq]->loot.resize(dummy);
            for(int l2=0;l2<len(squad[sq]->loot);l2++)
            {
               int itemLen;
               fread(&itemLen, sizeof(int), 1, h);
               vector<char> vec = vector<char>(itemLen + 1);
               fread(&vec[0], itemLen, 1, h);
               vec[itemLen] = '\0';

               Item* it = create_item(&vec[0]);
               //if(it!=NULL) //Assume save file is correct? -XML
                  squad[sq]->loot[l2] = it;
               /*else
                  squad[sq]->loot.erase(loot.begin()+l2--);*/
            }
            //Remove items of unknown type.
            for(int l2=len(squad[sq]->loot)-1; l2>=0; l2--)
            {
               bool del = false;
               if(squad[sq]->loot[l2]->is_loot())
                  del = (getloottype(squad[sq]->loot[l2]->get_itemtypename()) == -1);
               else if(squad[sq]->loot[l2]->is_clip())
                  del = (getcliptype(squad[sq]->loot[l2]->get_itemtypename()) == -1);
               else if(squad[sq]->loot[l2]->is_weapon())
                  del = (getweapontype(squad[sq]->loot[l2]->get_itemtypename()) == -1);
               else if(squad[sq]->loot[l2]->is_armor())
                  del = (getarmortype(squad[sq]->loot[l2]->get_itemtypename()) == -1);

               if(del)
               {
                  addstr("Item type ");
                  addstr(squad[sq]->loot[l2]->get_itemtypename());
                  addstr(" does not exist. Deleting item.");
                  delete_and_remove(squad[sq]->loot,l2);
               }
            }
            consolidateloot(squad[sq]->loot); // consolidate loot after loading
         }

         activesquad=NULL;
         fread(&dummy_b,sizeof(bool),1,h);
         if(dummy_b)
         {
            int dummy_i;
            fread(&dummy_i,sizeof(int),1,h);
            for(int sq=0;sq<len(squad);sq++)
               if(squad[sq]->id==dummy_i)
               {
                  activesquad=squad[sq];
                  break;
               }
         }

         //DATES
         fread(&dummy,sizeof(int),1,h);
         date.resize(dummy);
         for(int dt=0;dt<len(date);dt++)
         {
            date[dt]=new datest;

            fread(&date[dt]->mac_id,sizeof(long),1,h);
            fread(&date[dt]->timeleft,sizeof(short),1,h);
            fread(&date[dt]->city,sizeof(int),1,h);

            fread(&dummy,sizeof(int),1,h);
            date[dt]->date.resize(dummy);
            for(int dt2=0;dt2<len(date[dt]->date);dt2++)
            {
               int creatureLen;
               fread (&creatureLen, sizeof(int), 1, h);
               vector<char> vec = vector<char> (creatureLen + 1);
               fread (&vec[0], creatureLen, 1, h);
               vec[creatureLen] = '\0';
               date[dt]->date[dt2] = new Creature(&vec[0]);

               //date[dt]->date[dt2]=new Creature;
               //fread(date[dt]->date[dt2],sizeof(Creature),1,h);
            }
         }

         //RECRUITS
         fread(&dummy,sizeof(int),1,h);
         recruit.resize(dummy);
         for(int rt=0;rt<len(recruit);rt++)
         {
            recruit[rt]=new recruitst;
            fread(&recruit[rt]->recruiter_id,sizeof(long),1,h);
            fread(&recruit[rt]->timeleft,sizeof(short),1,h);
            fread(&recruit[rt]->level,sizeof(char),1,h);
            fread(&recruit[rt]->eagerness1,sizeof(char),1,h);
            fread(&recruit[rt]->task,sizeof(char),1,h);

            int creatureLen;
            fread (&creatureLen, sizeof(int), 1, h);
            vector<char> vec = vector<char> (creatureLen + 1);
            fread (&vec[0], creatureLen, 1, h);
            vec[creatureLen] = '\0';
            recruit[rt]->recruit = new Creature(&vec[0]);
            //recruit[rt]->recruit = new Creature;
            //fread(recruit[rt]->recruit,sizeof(Creature),1,h);
         }

         //NEWS STORIES
         fread(&dummy,sizeof(int),1,h);
         newsstory.resize(dummy);
         for(int ns=0;ns<len(newsstory);ns++)
         {
            newsstory[ns]=new newsstoryst;

            fread(&newsstory[ns]->type,sizeof(short),1,h);
            fread(&newsstory[ns]->view,sizeof(short),1,h);

            fread(&newsstory[ns]->loc,sizeof(long),1,h);
            fread(&newsstory[ns]->priority,sizeof(long),1,h);
            fread(&newsstory[ns]->page,sizeof(long),1,h);
            fread(&newsstory[ns]->positive,sizeof(char),1,h);
            fread(&newsstory[ns]->siegetype,sizeof(short),1,h);

            newsstory[ns]->cr=NULL;
            fread(&dummy_b,sizeof(bool),1,h);
            if(dummy_b)
            {
               fread(&dummy_l,sizeof(long),1,h);
               for(int pl=0;pl<len(pool);pl++)
                  if(pool[pl]->id==dummy_l)
                  {
                     newsstory[ns]->cr=pool[pl];
                     break;
                  }
            }

            fread(&dummy,sizeof(int),1,h);
            newsstory[ns]->crime.resize(dummy);
            for(int dt2=0;dt2<len(newsstory[ns]->crime);dt2++)
               fread(&newsstory[ns]->crime[dt2],sizeof(int),1,h);
         }

         // Liberal Media
         fread(public_interest,sizeof(public_interest),1,h);
         fread(background_liberal_influence,sizeof(background_liberal_influence),1,h);

         // Site mode options
         fread(&encounterwarnings,sizeof(bool),1,h);
         bool musicenabled;
         fread(&musicenabled,sizeof(bool),1,h);
         music.enableIf(musicenabled);

         LCSCloseFile(h);

         // Check that vehicles are of existing types.
         for(int v=0;v<len(vehicle);v++)
         {
            if(getvehicletype(vehicle[v]->vtypeidname())==-1)
            { //Remove vehicle of non-existing type.
               addstr("Vehicle type "+vehicle[v]->vtypeidname()+" does not exist. Deleting vehicle.");
               delete_and_remove(vehicle,v--);
            }
         }

         return 1;
      }

   gamelog.log("Could not load");
   return 0;
}
Exemple #5
0
/* saves a new high score */
void savehighscore(char endtype)
{
   loadhighscores();

   //MERGE THE STATS
   ustat_recruits+=stat_recruits;
   ustat_dead+=stat_dead;
   ustat_kills+=stat_kills;
   ustat_kidnappings+=stat_kidnappings;
   ustat_funds+=ledger.total_income;
   ustat_spent+=ledger.total_expense;
   ustat_buys+=stat_buys;
   ustat_burns+=stat_burns;

   //PLACE THIS HIGH SCORE BY DATE IF NECESSARY
   yourscore=-1;

   for(int s=0;s<SCORENUM;s++)
   {
      if((endtype==END_WON&&score[s].endtype==END_WON&&
         year==score[s].year&&month==score[s].month&&
         ledger.total_expense+ledger.total_expense>score[s].stat_spent+score[s].stat_funds)||

         (endtype==END_WON&&score[s].endtype==END_WON
         &&(year<score[s].year ||
         (year==score[s].year && month<score[s].month)))||

         (endtype==END_WON&&score[s].endtype!=END_WON)||

         (endtype!=END_WON&&score[s].endtype!=END_WON&&
         ledger.total_expense+ledger.total_income>score[s].stat_spent+score[s].stat_funds)||

         score[s].valid==0)
      {
         for(int s2=SCORENUM-1;s2>=s+1;s2--)
         {
            score[s2]=score[s2-1];
         }

         strcpy(score[s].slogan,slogan);
         score[s].month=month;
         score[s].year=year;
         score[s].stat_recruits=stat_recruits;
         score[s].stat_dead=stat_dead;
         score[s].stat_kills=stat_kills;
         score[s].stat_kidnappings=stat_kidnappings;
         score[s].stat_funds=ledger.total_income;
         score[s].stat_spent=ledger.total_expense;
         score[s].stat_buys=stat_buys;
         score[s].stat_burns=stat_burns;
         score[s].valid=1;
         score[s].endtype=endtype;

         yourscore=s;
         break;
      }
   }

   FILE *h=LCSOpenFile("score.dat","wb",LCSIO_PRE_HOME);
   if(h!=NULL)
   {
      int lversion=version;
      fwrite(&lversion,sizeof(int),1,h);

      fwrite(&ustat_recruits,sizeof(int),1,h);
      fwrite(&ustat_dead,sizeof(int),1,h);
      fwrite(&ustat_kills,sizeof(int),1,h);
      fwrite(&ustat_kidnappings,sizeof(int),1,h);
      fwrite(&ustat_funds,sizeof(int),1,h);
      fwrite(&ustat_spent,sizeof(int),1,h);
      fwrite(&ustat_buys,sizeof(int),1,h);
      fwrite(&ustat_burns,sizeof(int),1,h);
      fwrite(score,sizeof(highscorest),SCORENUM,h);

      LCSCloseFile(h);
   }
}