SLIC-Reference : GetNearestWater
CTP2 Bureau
The Modding
Knowledgebase
Apolyton CTP2 forums
Apolyton CTP2 archives
Source Code Project SVN

SLIC-Reference : : GetNearestWater  

Arguments: location, locationvar Type: void

Get the location of the nearest ocean square to location, putting the result in locationvar

Also returns the distance in patched version.

broken, obsolete ...  

Source:

SFN_ERROR Slic_GetNearestWater::Call(SlicArgList *args)
{
	m_result.m_int = 0;

	if(args->Count() != 2)
		return SFN_ERROR_NUM_ARGS;

	MapPoint pos;
	if(!args->GetPos(0, pos))
		return SFN_ERROR_TYPE_ARGS;

	sint32 x, y;
	MapPoint nearest;
	sint32 minDist = 0x7fffffff;

	for(y = 0; y < g_theWorld->GetYHeight(); y++) {
		for(x = 0; x < g_theWorld->GetXWidth(); x++) {
			if(!g_theWorld->IsWater(x,y))
				continue;
			MapPoint chk(x,y);
			sint32 dist = pos.NormalizedDistance(chk);
			if(dist < minDist) {
				minDist = dist;
				nearest.Set(x,y);
			}
		}
	}
	if(minDist >= 0x7fffffff) {
		
		return SFN_ERROR_OK;
	}

	if(args->m_argValue[1].m_type != SA_TYPE_INT_VAR) {
		return SFN_ERROR_TYPE_ARGS;
	}

	SlicSymbolData *sym = args->m_argValue[1].m_symbol;
	//Outcommented by Martin Ghmann
	//in order to fix this function
	//The porpose of this if statement is check whether 
	//the second argument is a location_t or not unfortunatly
	//it only accepts something's location like location[0].location.
	//But in this case SetPos function fails.
	//As it is now the function accepts also a city[0] as second argument
	//but can't fill it with a location obviously.
//	if(sym->GetType() == SLIC_SYM_LOCATION) {
		m_result.m_int = minDist;
		sym->SetPos(nearest);
		return SFN_ERROR_OK;
//	}
//	return SFN_ERROR_TYPE_ARGS;
}

More information available at Apolyton here

Information last updated by BureauBert on 26.06.2009

User Comments:

Using this form you may add your own observations concerning the above item, e.g. additional hints for usage, limitations, oddities etc. Please note this is not the place for asking questions or carrying out discussions about modding - please refer to the Apolyton CTP2 Modification Forum on that purpose.

Subject / Title*:
Text:*
(A maximum of characters left)
Your name:*
Your website (URL):

*) Required fields

Unkown Tag: NameUnkown Tag: Name

  Administration
This site is currently maintained by: BureauBert (Webmaster)  Maquiladora (Manager)  Legal Notice: Legal Notice Statistics: 123639 unique users since 02.05.2004 (» Site Statistics) Hosted by: WebhostOne
Share this page:  VK Facebook Twitter LiveJournal OK MR Google+ LinkedIn tumblr Pinterest Blogger Digg Evernote