Ejemplo n.º 1
0
Archivo: ospya.cpp Proyecto: mecirt/7k2
//--------- Begin of function SpyArray::add_spy ----------//
//
// This overloaded version of add_spy() just add a spy without
// setting parameters of the Spy.
//
// return: <int> recno of the spy record added
//
int SpyArray::add_spy()
{
	Spy spy;

	memset( &spy, 0, sizeof(spy) );

	linkin( &spy );

	((Spy*)get())->spy_recno = recno();

	return recno();
}
Ejemplo n.º 2
0
//-------- Begin of function GameFileArray::load_all_game_header --------//
//
// Load all headers of all saved game files in current directory.
//
void GameFileArray::load_all_game_header(const char *path, const char *extStr)
{
	int       i;
	Directory gameDir;
	GameFile  gameFile;
	File      file;

	// ##### begin Gilbert 26/5 ######//
	String str;
	if( path && path[0] != '\0' )
	{
		str = path;
		str += "/";
		str += extStr;
	}
	else
	{
		str = extStr;
	}

	// gameDir.read( player_profile.save_game_path(extStr), 1 );  // 1-Sort file names
	gameDir.read( str, 1 );  // 1-Sort file names

	//-------- read in the headers of all game sets -------//

	zap();

	for( i=1 ; i<=gameDir.size() ; i++ )
	{
		// Directory store file name without path
		if( path && path[0] != '\0' )
		{
			str = path;
			str += "/";
			str += gameDir[i]->name;
		}
		else
		{
			str = gameDir[i]->name;
		}

		if( file.file_open( str, 1, 1 )      // last 1=allow varying read & write size
			&& file.file_read(&gameFile, sizeof(GameFile))
			&& gameFile.validate_header() )
		{
			strcpy( gameFile.file_name, file.file_name );  // in case that the name may be different
			gameFile.file_date = gameDir[i]->time;
	      linkin(&gameFile);
		}
		file.file_close();
	}
	// ##### end Gilbert 26/5 ######//
}
Ejemplo n.º 3
0
//-------- Begin of function GameFileArray::save_new_game -----//
//
// Save current game to a new saved game file immediately without
// prompting menu.
//
// Called by GameFileArray::process_action() and error handler.
//
// [char*] fileName - file name of the saved game
//
// return : <int> 1 - saved successfully.
//                0 - not saved.
//
int GameFileArray::save_new_game(const char* fileName)
{
	GameFile  gameFile;
	GameFile* gameFilePtr;
	int       addFlag=1;
	int       gameFileRecno;

	memset( &gameFile, 0, sizeof(GameFile) );

	if( fileName )
	{
		//----- check for overwriting an existing file ----//

		for( gameFileRecno=1 ; gameFileRecno<=game_file_array.size() ; gameFileRecno++ )
		{
			gameFilePtr = game_file_array[gameFileRecno];

			if( strcmp(gameFilePtr->file_name, fileName)==0 )      // if this file name already exist
			{
				addFlag=0;
				break;
			}
		}

		strcpy( gameFile.file_name, fileName );
	}
	else
	{
		gameFile.set_file_name();        // give it a new game_file_name based on current group name
	}

	//----------- save game now ------------//

	if( gameFile.save_game(fileName) )
	{
		strcpy( last_file_name, gameFile.file_name );

		if( addFlag )
		{
			linkin(&gameFile);

			quick_sort( sort_game_file_function );
		}
		else
		{
			game_file_array.update(&gameFile, gameFileRecno);
		}

		return 1;
	}
	return 0;
}
Ejemplo n.º 4
0
int StudentArray::add(char studentLevel, char yearInProgram, char genderEthnicGroup, char stuSeg, char major, int finAid, float* talentArr) {
    Student student;

    student.init(studentLevel, yearInProgram, genderEthnicGroup, stuSeg, major, finAid, talentArr );

    linkin(&student);

    ((Student*)get())->student_recno = recno();

    student_count++;

    return recno();
}
Ejemplo n.º 5
0
//----- Begin of function TownArray::add_town -------//
//
// <int> nationRecno - the nation recno
// <int> raceId 	   - the race of the majority of the town poulation
// <int> xLoc, yLoc  - location of the town
//
int TownArray::add_town(int nationRecno, int raceId, int xLoc, int yLoc)
{
	Town* townPtr;

	townPtr = new Town;

	linkin(&townPtr);

	townPtr->town_recno = recno();
	townPtr->init(nationRecno, raceId, xLoc, yLoc);

	nation_array.update_statistic();		// update largest_town_recno

	return recno();
}
Ejemplo n.º 6
0
Archivo: ospya.cpp Proyecto: mecirt/7k2
//--------- Begin of function SpyArray::add_spy ----------//
//
// <int> unitRecno - unit recno of the spy
// <int> spySkill  - spying skill of the unit
// [int] trueNation - true nation recno (default -1:unit's nation)
//
// return: <int> recno of the spy record added
//
int SpyArray::add_spy(int unitRecno, int spySkill, int trueNation)
{
	Spy 	spy;
	Unit* unitPtr = unit_array[unitRecno];

	memset( &spy, 0, sizeof(spy) );

	spy.spy_place 			= SPY_MOBILE;
	spy.spy_place_para	= unitRecno;
	spy.spy_skill 			= spySkill;
	spy.spy_loyalty 		= unitPtr->loyalty;
	spy.race_id			   = unitPtr->race_id;
	spy.is_civilian		= unitPtr->is_civilian();
	spy.name_id				= unitPtr->name_id;
	// ####### begin Gilbert 24/2 #######//
	spy.unique_id        = unitPtr->unique_id;
	// ####### end Gilbert 24/2 #######//

	err_when( unitPtr->race_id < 1 || unitPtr->race_id > MAX_RACE );

	err_when( nation_array.is_deleted(unitPtr->nation_recno) );

	err_when( trueNation == 0 );
	if( trueNation < 0 )
		trueNation = unitPtr->nation_recno;

	spy.true_nation_recno    = trueNation;
	spy.cloaked_nation_recno = unitPtr->nation_recno;

	//--- spies hold a use right of the name id even though the unit itself will register the usage right of the name already ---//

	race_res[spy.race_id]->use_name_id(spy.name_id);		// the spy will free it up in deinit(). Keep an additional right because when a spy is assigned to a town, the normal program will free up the name id., so we have to keep an additional copy

	// ------- set camouflage vars --------//

	spy.camouflage_count = 0;
	spy.camouflage_power = spySkill / 4;

	//------- link in the spy_array -------//

	linkin( &spy );

	((Spy*)get())->spy_recno = recno();

	return recno();
}
Ejemplo n.º 7
0
//---------- BEGIN OF FUNCTION DynArray::insert -----------//
//
// Link into the position BEFORE the current one
//
// Warning : DynArrayB (version B) can't use this function
//
void DynArray::insert(void* ent) {
    if( size()==0 ) {
	linkin(ent);
	return;
    }

    last_ele++;

    if ( last_ele > ele_num )                       // not enough empty element left to hold the new entity
	resize( ele_num + block_num );

    memmove( body_buf+cur_pos*ele_size,body_buf+(cur_pos-1)*ele_size, (last_ele-cur_pos)*ele_size );

    if ( ent )
	memcpy(body_buf+(cur_pos-1)*ele_size, ent, ele_size );
    else
	*(body_buf+(cur_pos-1)*ele_size) = NULL;
}
Ejemplo n.º 8
0
//---------- BEGIN OF FUNCTION DynArray::insert_at -----------//
//
// Link into the position BEFORE the current one
//
// Warning : DynArrayB (version B) can't use this function
//
// <int>   insertPos - the recno to insert the new entity.
// <void*> ent		   - pointer to the record entity. If NULL, blank record.
//
void DynArray::insert_at(int insertPos, void* ent) {
    if( size()==0 || insertPos>last_ele ) {
	linkin(ent);
	return;
    }

    err_when( insertPos<1 || insertPos > last_ele );

    last_ele++;

    if ( last_ele > ele_num )                       // not enough empty element left to hold the new entity
	resize( ele_num + block_num );

    memmove( body_buf+insertPos*ele_size, body_buf+(insertPos-1)*ele_size, (last_ele-insertPos)*ele_size );

    if ( ent )
	memcpy(body_buf+(insertPos-1)*ele_size, ent, ele_size );
    else
	*(body_buf+(insertPos-1)*ele_size) = NULL;
}
Ejemplo n.º 9
0
//-------- Begin of function GameFileArray::load_all_game_header --------//
//
// Load all headers of all saved game files in current directory.
//
void GameFileArray::load_all_game_header(const char *extStr)
{
	char full_path[MAX_PATH+1];
	int       i;
	Directory gameDir;
	GameFile  gameFile;
	File      file;

	if (!misc.path_cat(full_path, sys.dir_config, extStr, MAX_PATH))
	{
		ERR("Path to the config directory too long.\n");
		return;
	}
	gameDir.read(full_path, 0);  // 0-Don't sort file names

	//-------- read in the headers of all game sets -------//

	zap();

	for( i=1 ; i<=gameDir.size() ; i++ )
	{
		if (!misc.path_cat(full_path, sys.dir_config, gameDir[i]->name, MAX_PATH))
		{
			ERR("Path to the saved game too long.\n");
			continue;
		}
		if( file.file_open(full_path, 1, 1)      // last 1=allow varying read & write size
			&& file.file_read(&gameFile, sizeof(GameFile))
			&& gameFile.validate_header() )
		{
			strcpy( gameFile.file_name, gameDir[i]->name );  // in case that the name may be different
			gameFile.file_date = gameDir[i]->time;
	      linkin(&gameFile);
		}
		file.file_close();
	}

	quick_sort( sort_game_file_function );
}
Ejemplo n.º 10
0
Archivo: odir.cpp Proyecto: 112212/7k2
//------- Begin of function Directory::read -------//
//
// Read in the file list of the specified file spec.
//
// <char*> fileSpec = the file spec of the directory
// [int]   sortName = sort the file list by file name
//                    (default : 0)
//
// return : <int> the no. of files matched the file spec.
//
int Directory::read(const char *fileSpec, int sortName)
{
   FileInfo				fileInfo;
#ifndef NO_WINDOWS
	WIN32_FIND_DATA	findData;
   
   //----------- get the file list -------------//

   HANDLE findHandle = FindFirstFile( fileSpec, &findData );

   while(findHandle!=INVALID_HANDLE_VALUE)
   {
      misc.extract_file_name( fileInfo.name, findData.cFileName );		// get the file name only from a full path string

      fileInfo.size = findData.nFileSizeLow;
      fileInfo.time = findData.ftLastWriteTime; 

      linkin( &fileInfo );

      if( !FindNextFile( findHandle, &findData ) )
			break;
   }

	FindClose(findHandle);

   //------ the file list by file name ---------//

   if( sortName )
      quick_sort( sort_file_function );

#else

   MSG("Listing Directory %s sortName=%d\n", fileSpec, sortName);

   char dirname[MAX_PATH];
   char search[MAX_PATH];
   struct dirent **namelist;
   int n;

   char *slash = strrchr((char*)fileSpec, '/');
   if (slash)
   {
      char *s = (char*)fileSpec;
      char *d = dirname;
      int i = 0;
      while (s != slash && i < MAX_PATH - 1)
      {
         if (*s == '\\')
            *d = '/';
         else if (isalpha(*s))
            *d = tolower(*s);
         else
            *d = *s;
         d++;
         s++;
         i++;
      }
      *d = 0;

      i = 0;
      d = search;
      s++;
      while (*s && i < MAX_PATH - 1)
      {
         if (*s == '*')
         {
            s++;
            i++;
            continue;
         }
         else if (isalpha(*s))
         {
            *d = tolower(*s);
         }
         else
         {
            *d = *s;
         }
         d++;
         s++;
         i++;
      }
      *d = 0;
   } else {
      char *s = (char*)fileSpec;
      char *d = search;
      int i = 0;

      while (*s && i < MAX_PATH - 1)
      {
         if (*s == '*')
         {
            s++;
            i++;
            continue;
         }
         else if (isalpha(*s))
         {
            *d = tolower(*s);
         }
         else
         {
            *d = *s;
         }
         d++;
         s++;
         i++;
      }
      *d = 0;


      dirname[0] = '.';
      dirname[1] = 0;
   }

   MSG("directory=%s search=%s\n", dirname, search);
   n = scandir(dirname, &namelist, 0, alphasort);
   for (int i = 0; i < n; i++)
   {
      char filename[MAX_PATH];
      char *s = namelist[i]->d_name;
      char *d = filename;
      int j = 0;
      while (*s && j < MAX_PATH - 1)
      {
         if (isalpha(*s))
            *d = tolower(*s);
         else
            *d = *s;
         d++;
         s++;
         j++;
      }
      *d = 0;

      if (strstr(filename, search))
      {
         char full_path[MAX_PATH];
         struct stat file_stat;

         full_path[0] = 0;
         strcat(full_path, dirname);
         strcat(full_path, "/");
         strcat(full_path, namelist[i]->d_name);

         stat(full_path, &file_stat);

         strncpy(fileInfo.name, namelist[i]->d_name, MAX_PATH - 2);

         fileInfo.size = file_stat.st_size;
         fileInfo.time.dwLowDateTime = 0;
         fileInfo.time.dwHighDateTime = 0;

         linkin( &fileInfo );
      }
      free(namelist[i]);
   }
   if (n > -1)
     free(namelist);

#endif

   return size();       // DynArray::size()
}
Ejemplo n.º 11
0
//-------- Begin of function GameFileArray::save_new_game -----//
//
// Save current game to a new saved game file immediately without
// prompting menu.
//
// Called by GameFileArray::process_action() and error handler.
//
// <char*> fileName - file name of the saved game
//
// return 1 - success
//        0 - cancel
//       -1 - fail
//
// ###### begin Gilbert 20/1 ########//
int GameFileArray::save_new_game(const char* fileName)
{
	GameFile  gameFile;
	GameFile* gameFilePtr;
	int       addFlag=1;
	int       gameFileRecno;

	memset( &gameFile, 0, sizeof(GameFile) );

	if( fileName )		// has a filename before extension
	{
		load_all_game_header( save_default_dir, save_default_ext );

		// ### begin Gilbert 26/5 #####//
		// fileName = player_profile.save_game_path(fileName);
		// ### end Gilbert 26/5 #####//

		if( save_default_dir[0] != '\0' )
		{
			strcpy( gameFile.file_name, save_default_dir );
			strcat( gameFile.file_name, "/" );
			strcat( gameFile.file_name, fileName );
		}
		else
		{
			strcpy( gameFile.file_name, fileName );
		}

		// if fileName without extension append

		if( !strchr(fileName, '.' ) )
		{
			strcat(gameFile.file_name, strchr( save_default_ext, '.') );		// remove '*' of "*.SAV"
		}

		//----- check for overwriting an existing file ----//

		for( gameFileRecno=1 ; gameFileRecno<=game_file_array.size() ; gameFileRecno++ )
		{
			gameFilePtr = game_file_array[gameFileRecno];

			// ###### begin Gilbert 31/10 ######//
			if( strcasecmp(gameFilePtr->file_name, gameFile.file_name)==0 )      // if this file name already exist
			// ###### end Gilbert 31/10 ######//
			{
				addFlag=0;
				break;
			}
		}
		// strcpy( gameFile.file_name, fileName );		// now use gameFile.file_name instead
   }
	else
   {
		load_all_game_header( save_default_dir, save_default_ext );

		// find the extension begin with '.'
		err_when( !strchr(save_default_ext, '.') );
      gameFile.set_file_name(save_default_dir, strchr(save_default_ext, '.') );        // give it a new game_file_name based on current group name
   }

	// --------- ask description -------//

	if( !gameFile.ask_desc() )
		return 0;

	//----------- save game now ------------//

	if( gameFile.save_game(save_default_dir, NULL, NULL) )		// use gameFile.file_name
	{
		strcpy( last_file_name, gameFile.file_name );

		if( addFlag )
		{
         linkin(&gameFile);

			quick_sort( sort_game_file_function );
      }
		else
      {
			// #### begin Gilbert 31/10 ######//
         update(&gameFile, gameFileRecno);
			// #### end Gilbert 31/10 ######//
      }

		return 1;
   }

	return -1;

	// ###### end Gilbert 20/1 ########//
}
Ejemplo n.º 12
0
//--------- Begin of function FirmArray::create_firm ---------//
//
// create_firm() will be called directly by :
//
// 1. FirmArray::build_firm()  for setting up a new firm
// 2. FirmArray::read_file() when loading game.
//
// <int> firmId = firm type id
//
// Return : <int> the record no. of the newly added firm
//
int FirmArray::create_firm(int firmId)
{
	Firm* firmPtr;

//	static char firmAnimalTrainArray[] = { UNIT_JAGUAR, UNIT_GORILLA, UNIT_RHINO, 0 };
	static char firmIncubatorTrainArray[] = { UNIT_BALLISTA, UNIT_CATAPULT, UNIT_CANNON, 0 };

	switch(firmId)
	{
		case FIRM_BASE:
			firmPtr = new FirmBase;
			break;

		case FIRM_FORT:
			firmPtr = new FirmFort;
			break;

		case FIRM_CAMP:
			firmPtr = new FirmCamp;
			break;

		case FIRM_FACTORY:
			firmPtr = new FirmFactory;
			break;

		case FIRM_INN:
			firmPtr = new FirmInn;
			break;

		case FIRM_MARKET:
			firmPtr = new FirmMarket;
			break;

		case FIRM_MINE:
			firmPtr = new FirmMine;
			break;

		case FIRM_RESEARCH:
			firmPtr = new FirmResearch;
			break;

		case FIRM_WAR_FACTORY:
			firmPtr = new FirmWar;
			break;

//		case FIRM_HARBOR:
//			firmPtr = new FirmHarbor;
//			break;

		case FIRM_SPY:
			firmPtr = new FirmSpy;
			break;

		case FIRM_SPECIAL:
			firmPtr = new FirmSpecial;
			break;

		case FIRM_LAIR:
			firmPtr = new FirmLair;
			break;

		case FIRM_BEE:
			firmPtr = new FirmMonsterTrain(UNIT_BEE);
			break;

		case FIRM_TERMITE:
			firmPtr = new FirmMonsterTrain(UNIT_TERMITE);
			break;
		
		case FIRM_LISHORR:
		case FIRM_WILDE_LISHORR:
			firmPtr = new FirmLishorr;
			break;

		case FIRM_ALCHEMY:
			firmPtr = new FirmMonsterAlchemy;
			break;

		case FIRM_INCUBATOR:
			firmPtr = new FirmIncubator;
			break;

		case FIRM_ANIMAL:
			firmPtr = new FirmAnimal;
			break;

		case FIRM_FORTRESS:
			firmPtr = new FirmMonsterFortress(UNIT_ROCK);
			break;

		case FIRM_MAGIC:
			firmPtr = new FirmMagic;
			break;

		case FIRM_OFFENSIVE_BUILDING_1:
		case FIRM_OFFENSIVE_BUILDING_2:
		case FIRM_OFFENSIVE_BUILDING_4:
			firmPtr = new FirmOffensive;
			break;

		case FIRM_OFFENSIVE_BUILDING_3:	
			firmPtr = new FirmOffensive2;
			break;

		default:
			err_now("FirmArray::create_firm()");
	}
 
	//----------------------------------------//

	linkin(&firmPtr);
	firmPtr->firm_recno = recno();

	return firmPtr->firm_recno;
}
Ejemplo n.º 13
0
int FirmDieArray::add(FirmDie *r)
{
	linkin(r);
	return recno();
}
Ejemplo n.º 14
0
Archivo: osite.cpp Proyecto: 112212/7k2
//--------- Begin of function SiteArray::add_site ---------//
//
// Add a raw item to the site array
//
// If the given location is occupied, it will locate a closest empty
// location to add the item.
//
// <int> xLoc, yLoc - the location of the site
// <int> siteType	  - site type
// <int> objectId   - site parameter
// [int] reserveQty - reserve qty, for raw site only
//
// Return : >0 - the recno of the site.
//          0  - duplicated, not added
//
int SiteArray::add_site(int xLoc, int yLoc, int siteType, int objectId, int reserveQty)
{
	//---- check if the given location is empty ----//

	int foundFlag = 0;

	int siteWidth = 1;
	int siteHeight = 1;
	int gapSpace = 0;
	if( siteType == SITE_RAW )
	{
		siteWidth = raw_res[objectId]->map_loc_width;
		siteHeight = raw_res[objectId]->map_loc_height;
		gapSpace = INTER_PLACE_SPACE;
	}

	if( world.can_build_site(xLoc, yLoc, siteWidth, siteHeight, gapSpace) )
	{
		foundFlag = 1;
	}
	else
	{
		//------ locate for empty space to add the item -------//

		#define ADD_SITE_RANGE	5

		int		 xOffset, yOffset;
		int		 curXLoc = xLoc, curYLoc = yLoc;
		Location* locPtr;
		BYTE	 	 regionId = world.get_region_id(curXLoc, curYLoc);

		for( int i=1 ; i<ADD_SITE_RANGE*ADD_SITE_RANGE ; i++ )
		{
			misc.cal_move_around_a_point(i, ADD_SITE_RANGE, ADD_SITE_RANGE, xOffset, yOffset);

			xLoc = curXLoc + xOffset;
			yLoc = curYLoc + yOffset;

			xLoc = MAX(0, xLoc);
			xLoc = MIN(MAX_WORLD_X_LOC-siteWidth, xLoc);

			yLoc = MAX(0, yLoc);
			yLoc = MIN(MAX_WORLD_Y_LOC-siteHeight, yLoc);

			locPtr = world.get_loc(xLoc, yLoc);

			if( world.can_build_site(xLoc, yLoc, siteWidth, siteHeight, gapSpace) 
				&& locPtr->region_id==regionId )
			{
				foundFlag = 1;
				break;
			}
		}
	}

	if( !foundFlag )
		return 0;

	//----- linkin the raw and update raw attribute ----//

	Site site;

	linkin(&site);

	Site* sitePtr = (Site*) get(recno());

	// #### begin Gilbert 1/2 ######//
	Location *locPtr = NULL;
	if( sizeof(locPtr->extra_para)==sizeof(unsigned char)
		&& recno() > 0xff )
	{
		linkout();
		return 0;
	}
	// #### end Gilbert 1/2 ######//

	sitePtr->init(recno(), siteType, xLoc, yLoc);

	sitePtr->object_id 	= objectId;
	sitePtr->reserve_qty = reserveQty;

	switch( siteType )
	{
		case SITE_RAW:
			untapped_raw_count++;
			break;

		case SITE_SCROLL:
			scroll_count++;
			break;

		case SITE_GOLD_COIN:
		{
			sitePtr->animation_count = 5;
			gold_coin_count++;
			break;
		}
		case SITE_ITEM:
			item_count++;
			break;

		case SITE_WEAPON_BLUEPRINT:
			weapon_blueprint_count++;
			break;
	}

	return sitePtr->site_recno;
}
Ejemplo n.º 15
0
//--------- Begin of function UnitGroup::add_unit ---------//
//
void UnitGroup::add_unit(short unitRecno)
{
	err_when( unit_array.is_deleted(unitRecno) );

	linkin(&unitRecno);
}
Ejemplo n.º 16
0
void SpriteArray::add(Sprite *newSprite)
{
	linkin(&newSprite);

	newSprite->sprite_recno = recno();
}