Exemple #1
0
//--------- Begin of function SiteArray::del_site ----------//
//
// Delete a specified site.
//
// <int> siteRecno = the record no. of the site to be deleted
//
void SiteArray::del_site(int siteRecno)
{
	err_if( siteRecno == 0 )
		err_now( "SiteArray::del_site" );

	Site* sitePtr = site_array[siteRecno];

	switch( sitePtr->site_type )
	{
		case SITE_RAW:
			untapped_raw_count--;
			break;

		case SITE_SCROLL:
			scroll_count--;
			break;

		case SITE_GOLD_COIN:
			gold_coin_count--;
			break;
	}

	//-------------------------------//

	sitePtr->deinit();

	linkout(siteRecno);

	if( siteRecno == site_array.selected_recno )
		site_array.selected_recno = 0;
}
Exemple #2
0
void SpriteArray::del(int recNo)
{
	Sprite* spritePtr = (Sprite*) get_ptr(recNo);

	err_when( !spritePtr );

	delete spritePtr;

	linkout(recNo);
}
Exemple #3
0
//----- Begin of function TownArray::del_town -------//
//
void TownArray::del_town(int townRecno)
{
	Town* townPtr = operator[](townRecno);

	townPtr->deinit();
	delete townPtr;

	linkout(townRecno);

	nation_array.update_statistic();
}
Exemple #4
0
void TownNetworkArray::remove_network(int recno)
{
	if (recno < 0 || recno > size())
	{
		if (DEBUG_CHECK) throw "Invalid recno passed to remove_network";
		else return;
	}

	TownNetwork *pNetwork = network(recno);
	if (DEBUG_CHECK && pNetwork == NULL) throw "Town Network has already been removed";
	delete pNetwork; // deleting null is safe
	linkout(recno);
}
Exemple #5
0
void StudentArray::del(int recNo) {
    // BUG FIXED in Version 2.0
    Student *ptr = (Student*) get(recNo);

    // avoid bug 2107
    if(!ptr)
	return;                                       // temp use
    //	err_when(!ptr);

    //##### begin fred 980915 #####//
    student_count--;
    //##### end fred 980915 #####//
    linkout(recNo);
}
Exemple #6
0
void GameFileArray::del_game()
{
	int recNo = browse_recno;

//	if( !box.ask( "This saved game will be deleted, proceed ?" ) )
	if( !box.ask( text_game_menu.str_ask_delete_save()) )
		return;

	//---------------------------------------------------//

	unlink(game_file_array[recNo]->file_name);   // unlink() is a C standard function in io.h, for delete file

	go(recNo);
	linkout();

	go(recNo-1);    // skip back one record
}
Exemple #7
0
//--------- Begin of function NationArray::del_nation ---------//
//
// <int> recNo = the no. of the record to be deleted
//               (default : current record no.)
//
void NationArray::del_nation(int recNo)
{
	//-----------------------------------------//

	Nation* nationPtr = nation_array[recNo];       // operator[] will check for deleted nation error, can't use operator() because it use firm_array()->nation_recno

	nation_count--;

	if( nationPtr->nation_type == NATION_AI )
		ai_nation_count--;

	last_del_nation_date = info.game_date;

	//------ delete and linkout the nation ------//

	nationPtr->deinit();

	delete nationPtr;

	go(recNo);

	*( (Nation**) get() ) = NULL;   // Nullify the pointer
	linkout();

	//--- if the nation to be deleted is the player's nation ---//

	// ####### begin Gilbert 26/7 #########//
	if( recNo==player_recno )
	{
		player_ptr   = NULL;
		player_recno = 0;

		if( !sys.signal_exit_flag )
			sys.set_view_mode(MODE_NORMAL);		// set the view mode to normal mode to prevent possible problems
	}

	if( !sys.quick_exit_flag() )
	{
		//---------- update statistic ----------//
		update_statistic();		// as max_overall_nation_recno and others may be pointing to the deleted nation
	}
	// ####### end Gilbert 26/7 #########//
}
Exemple #8
0
//------ Begin of function NewsArray::remove -----//
//!
//! Remove a specific news from the news_array.
//!
//! <int> newsId     = id. of the news
//! <int> shortPara1 = short_para1 of the news
//!
void NewsArray::remove(int newsId, int shortPara1) {
    News* newsPtr;

    for( int i=size() ; i>0 ; i-- ) {
	newsPtr = news_array[i];

	if( newsPtr->id == newsId &&
	    newsPtr->short_para1 == shortPara1 ) {
	    linkout(i);

	    //### begin alex 31/3 ###//
	    //if( i<last_clear_recno && last_clear_recno > 1 )
	    if( i<=last_clear_recno && last_clear_recno > 0 )
		last_clear_recno--;
	    //#### end alex 31/3 ####//

	    break;
	}
    }
}
Exemple #9
0
//--------- Begin of function SpriteArray::deinit ---------//
//
// All firms should be deleted when the system terminated
//
// Chain : delete nation --> delete firm --> delete job --> delete item
//
// Some data is corrupted when the some firms still exist when
// the system terminated
//
void SpriteArray::deinit()
{
	if( size()==0 )
		return;

	//----- delete sprite objects ------//

	for( int i=1 ; i<=size() ; i++ )
	{
		Sprite* spritePtr = (Sprite*) get_ptr(i);

		if( spritePtr )
			delete spritePtr;

		linkout(i);
	}

	//-------- zap the array -----------//

	zap();
}
Exemple #10
0
//--------- Begin of function FirmArray::del_firm ---------//
//
// Warning : After calling this function, the recno() is still
//           pointing to the deleted record.
//           So go() to a new record to prevent running NULL object
//
// <int> recNo = the no. of the record to be deleted
//               (default : current record no.)
//
void FirmArray::del_firm(int recNo)
{
   Firm* firmPtr = firm_array[recNo];

	//--- del its link from base_obj_array ----//

	base_obj_array.del(firmPtr->base_obj_recno);

	//---- delete the object and detach it from firm_array ---//

	int	xLoc = firmPtr->center_x;
	int	yLoc = firmPtr->center_y;

	if( !sys.quick_exit_flag() )
		firmPtr->deinit();

	delete firmPtr;

	linkout(recNo);

//	world.plant_limit = world.plant_limit + m.random(5);
}
Exemple #11
0
void GameFileArray::del_game()
{
	char full_path[MAX_PATH+1];
	int recNo = browse_recno;

	if( !box.ask( _("This saved game will be deleted, proceed ?") ) )
		return;

	//---------------------------------------------------//

	if (!misc.path_cat(full_path, sys.dir_config, game_file_array[recNo]->file_name, MAX_PATH))
	{
		ERR("Path to the saved game too long.\n");
		return;
	}

	unlink(full_path);   // unlink() is a C standard function in io.h, for delete file

	go(recNo);
	linkout();

	go(recNo-1);    // skip back one record
}
Exemple #12
0
//--------- Begin of function SpyArray::del_spy ----------//
//
// <int> spyRecno - recno of the spy to be deleted
//
void SpyArray::del_spy(int spyRecno)
{
	spy_array[spyRecno]->deinit();

	linkout(spyRecno);
}
Exemple #13
0
void FirmDieArray::del(int i)
{
	linkout(i);
}
Exemple #14
0
//--------- 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;
}
Exemple #15
0
//--------- Begin of function UnitGroup::del_unit ---------//
//
void UnitGroup::del_unit(short recNo)
{
	err_when( recNo < 1 || recNo > size() );

	linkout(recNo);
}