Exemplo n.º 1
0
//--------- Begin of function SiteArray::add_site ---------//
//
// Add a raw item to the site array
//
// Return : 1 - the raw is added
//          0 - duplicated, not added
//
int SiteArray::add_site(int xLoc, int yLoc, int siteType, int objectId, int reserveQty)
{
	//----- linkin the raw and update raw attribute ----//

	Site site;

	linkin(&site);

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

	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:
			gold_coin_count++;
			break;
	}

	return 1;
}
Exemplo n.º 2
0
Arquivo: osite.cpp Projeto: 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;
}