|
Arguments:
|
owner, nearlocation, distance[, savecity]
|
Type:
|
int
|
|
Same as CreateCity, but always finds a square next to ocean
|
|
This is most useful if you want to be able to build ships.
|
Source:
SFN_ERROR Slic_CreateCoastalCity::Call(SlicArgList *args)
{
if (args->Count() < 3 || args->Count() > 4)
return SFN_ERROR_NUM_ARGS;
sint32 owner;
if(!args->GetPlayer(0, owner)) {
return SFN_ERROR_TYPE_ARGS;
}
MapPoint pos;
if(!args->GetPos(1, pos))
return SFN_ERROR_TYPE_ARGS;
sint32 distance;
if(!args->GetInt(2, distance))
return SFN_ERROR_TYPE_ARGS;
sint32 x, y;
BOOL found = FALSE;
static DynamicArray legalPoints;
legalPoints.Clear();
sint16 origContinent = g_theWorld->GetContinent(pos);
for(x = 0; x < g_theWorld->GetXWidth(); x++) {
for(y = 0; y < g_theWorld->GetYHeight(); y++) {
MapPoint chk(x, y);
if(g_theWorld->GetContinent(chk) == origContinent &&
!g_theWorld->IsNextToCity(chk) &&
!g_theWorld->IsCity(chk) &&
g_theWorld->IsNextToWater(chk.x, chk.y)) {
legalPoints.Insert(chk);
found = TRUE;
}
}
}
if(!found) {
m_result.m_int = 0;
return SFN_ERROR_OK;
}
sint32 bestDistance = 0x7fffffff;
sint32 bestDiff = 0x7fffffff;
sint32 i;
for(i = 0; i < legalPoints.Num(); i++) {
sint32 dist = pos.NormalizedDistance(legalPoints[i]);
if(abs(distance - dist) < bestDiff) {
bestDiff = abs(distance - dist);
bestDistance = dist;
}
}
for(i = legalPoints.Num() - 1; i >= 0; i--) {
sint32 dist = pos.NormalizedDistance(legalPoints[i]);
if(dist != bestDistance) {
legalPoints.DelIndex(i);
}
}
MapPoint cpos;
cpos = legalPoints[g_rand->Next(legalPoints.Num())];
const UnitRecord *rec;
for(i = 0; i < g_theUnitDB->NumRecords() - 1; i++) {
rec = g_theUnitDB->Get(i, g_player[owner]->GetGovernmentType());
if(!rec->GetHasPopAndCanBuild())
continue;
if((g_theWorld->IsLand(cpos) || g_theWorld->IsMountain(cpos)) &&
!g_theWorld->IsWater(cpos) && rec->GetMovementTypeLand())
break;
if(g_theWorld->IsWater(cpos) && rec->GetMovementTypeSea())
break;
if(g_theWorld->IsSpace(cpos) && rec->GetMovementTypeSpace())
break;
}
if(i >= g_theUnitDB->NumRecords() - 1) {
m_result.m_int = 0;
return SFN_ERROR_OK;
}
Unit city = g_player[owner]->CreateCity(i, cpos,
CAUSE_NEW_CITY_SCENARIO,
NULL, -1);
if(city.m_id == 0) {
m_result.m_int = 0;
return SFN_ERROR_OK;
}
m_result.m_int = 1;
if(args->Count() > 3) {
if(args->m_argValue[3].m_type == SA_TYPE_INT_VAR) {
SlicSymbolData *sym = args->m_argValue[3].m_symbol;
if(sym->GetType() == SLIC_SYM_CITY) {
sym->SetCity(city);
}
}
}
return SFN_ERROR_OK;
} |
Information last updated by BureauBert on 23.11.2010
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.
*) Required fields
Unkown Tag: NameUnkown Tag: NameUnkown Tag: NameUnkown Tag: NameUnkown Tag: NameUnkown Tag: NameUnkown Tag: NameUnkown Tag: NameUnkown Tag: NameUnkown Tag: Name
|