//::///////////////////////////////////////////////
//:: Area Include File
//:: area_inc
//:: Copyright (c) 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*
GetArea(), GetFirstArea() functions.
Used in conjunction with the Area Place Holder
placeable. If you want your area to show up in
the list of areas, you must include this placeable
somewhere in your area.
*/
//:://////////////////////////////////////////////
//:: Created By: MJ
//:: Created On: 12/21/04
//:://////////////////////////////////////////////
// Area Size Constants
const int MaxAreaSizeX = 32;
const int MaxAreaSizeY = 32;
string AREA_DESIGNATOR_TAG = "area_designator";
const string AREA_LIST_PREFIX = "AREA_";
const string AREA_LIST_COUNT = "AREA_COUNT";
const string AREA_LIST_RESREF = "AREA_RESREF";
const string AREA_LIST_TAG = "AREA_TAG";
const string AREA_LIST_POINTER = "AREA_LIST_POINTER";
string TokenToString(string sToken, string sTargetString, string sDelimiter = "|")
{
return (sTargetString != "") ? sTargetString + sDelimiter + sToken : sToken;
}
//------------------------------------------------------------------------------
// Initialize the modules list of areas.
//------------------------------------------------------------------------------
void InitializeAreaList();
void InitializeAreaList()
{
object oModule = GetModule();
object oArea; string sName; string sTag; string sResRef;
string sTemp; string sDes;
object oAreaList = GetObjectByTag("AreaList");
int nNth = 0;
object oDesignator = GetObjectByTag(AREA_DESIGNATOR_TAG,nNth);
while (GetIsObjectValid(oDesignator))
{
oArea = GetArea(oDesignator);
SetLocalObject(oModule, AREA_LIST_PREFIX+IntToString(nNth), oArea);
sName = GetName(oArea); sTag = GetTag(oArea); sResRef = GetResRef(oArea);
sResRef = TokenToString(GetLocalString(oModule, AREA_LIST_RESREF), sResRef);
sTag = TokenToString(GetLocalString(oModule, AREA_LIST_TAG), sTag);
sDes = sName+" ("+sTag+")";
sDes = TokenToString(GetDescription(oAreaList), sDes);
SetLocalString(oAreaList, AREA_LIST_RESREF, sResRef);
SetLocalString(oAreaList, AREA_LIST_TAG, sTag);
SetDescription(oAreaList, sDes, TRUE);
SetPlotFlag(oDesignator,FALSE);
DestroyObject(oDesignator);
nNth++;
oDesignator = GetObjectByTag(AREA_DESIGNATOR_TAG,nNth);
}
SetLocalInt(oModule,AREA_LIST_COUNT,(nNth));
}
//------------------------------------------------------------------------------
// Provides direct access to area nIdx in the modules area list
//------------------------------------------------------------------------------
object GetAreaByIndex(int nIdx);
object GetAreaByIndex(int nIdx)
{
object oRet = GetLocalObject(GetModule(), AREA_LIST_PREFIX+IntToString(nIdx));
AreaDebug(GetName(oRet));
return oRet;
}
//------------------------------------------------------------------------------
// Return the First Area in the Modules Arealist
//------------------------------------------------------------------------------
object GetFirstArea();
object GetFirstArea()
{
SetLocalInt (GetModule(), AREA_LIST_POINTER,0);
object oRet = GetAreaByIndex(0);
AreaDebug(GetName(oRet));
return oRet;
}
//------------------------------------------------------------------------------
// Return the Next Area in the Modules Arealist
//------------------------------------------------------------------------------
object GetNextArea();
object GetNextArea()
{
int nIdx = GetLocalInt (GetModule(),AREA_LIST_POINTER);
nIdx++;
object oRet = GetAreaByIndex(nIdx);
SetLocalInt (GetModule(),AREA_LIST_POINTER,nIdx);
AreaDebug(GetName(oRet));
return oRet;
}
//------------------------------------------------------------------------------
// Return the number of areas in the module
//------------------------------------------------------------------------------
int GetAreaCount();
int GetAreaCount()
{
int nRet = GetLocalInt(GetModule(),AREA_LIST_COUNT);
AreaDebug(IntToString(nRet));
return nRet;
}
//------------------------------------------------------------------------------
// Returns a random location within the specified area.
//------------------------------------------------------------------------------
location AreaRandomLocation(object oArea);
location AreaRandomLocation(object oArea)
{
location lLoc;
int nRanX, nRanY, nRanZ;
nRanX = Random(MaxAreaSizeX);
nRanY = Random(MaxAreaSizeY);
nRanZ = 0; // Random(MaxAreaSizeZ);
float fX = IntToFloat(nRanX);
float fY = IntToFloat(nRanY);
float fZ = IntToFloat(nRanZ);
vector vVec = Vector(fX, fY, fZ);
lLoc = Location(oArea, vVec, 0.0);
return lLoc;
}
object GetAreaByResRef(string sResRef)
{
object oResult = GetFirstArea();
while (GetIsObjectValid(oResult) == TRUE)
{
if (GetResRef(oResult) == sResRef)
return oResult;
oResult = GetNextArea();
}
return OBJECT_INVALID;
}
// Comment, Dunahan: Copied to this Inc, from OR System for Isladora
// Moved to a seperate inc to prevent a circular dependency error
/*********************\
* Function Prototypes *
\*********************/
/**
* This function will get the width of the area passed in.
*
* Created By: Zaddix
* Created On: July 17, 2002
* Optimized: March , 2003 by Knat
*
* @param oArea The area to get the width of.
* @return The width of oArea, as number of tiles. One tile = 10 meters.
*/
int GetAreaWidth(object oArea);
/**
* This function will get the height of the area passed in.
*
* Created By: Zaddix
* Created On: July 17, 2002
* Optimized: March , 2003 by Knat
*
* @param oArea The area to get the height of.
* @return The height of oArea, as number of tiles. One tile = 10 meters.
*/
int GetAreaHeight(object oArea);
//////////////////////////////////////////////////
/* Include section */
//////////////////////////////////////////////////
/**********************\
* Function Definitions *
\**********************/
int GetAreaWidth(object oArea)
{
int nX = GetLocalInt(oArea,"#WIDTH");
if( nX == 0)
{
int nY = 0; int nColor;
for (nX = 0; nX < 32; ++nX)
{
nColor = GetTileMainLight1Color(Location(oArea, Vector(IntToFloat(nX), 0.0, 0.0), 0.0));
if (nColor < 0 || nColor > 255)
{
SetLocalInt(oArea,"#WIDTH", nX);
return(nX);
}
}
SetLocalInt(oArea,"#WIDTH", 32);
return 32;
}
else
return nX;
}
int GetAreaHeight(object oArea)
{
int nY = GetLocalInt(oArea,"#HEIGHT");
if( nY == 0)
{
int nX = 0; int nColor;
for (nY=0; nY<32; ++nY)
{
nColor = GetTileMainLight1Color(Location(oArea, Vector(0.0, IntToFloat(nY), 0.0),0.0));
if (nColor < 0 || nColor > 255)
{
SetLocalInt(oArea,"#HEIGHT",nY);
return(nY);
}
}
SetLocalInt(oArea,"#HEIGHT",32);
return 32;
}
else
return nY;
}