188 lines
7.0 KiB
Plaintext
188 lines
7.0 KiB
Plaintext
////////////////////////////////////////////////////////////////////////////////
|
|
// area_hb_clean - Cleaning Routine to improve stability
|
|
// By Deva B. Winblood. November 13th, 2008.
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
/*
|
|
nCleanUpMode 0 = Default
|
|
1 = Aggressive - if player leaves area destroy everything
|
|
but, plot items, artifacts, mana crystals, and items
|
|
worth more than the threshold.
|
|
2 = Disabled
|
|
nCleanThreshold 0 = Default 100 gold
|
|
# = gold amount
|
|
*/
|
|
|
|
int fnAbsoluteHour()
|
|
{ // PURPOSE: Return Absolute Hour
|
|
return GetTimeHour()+(GetCalendarDay()*24)+(GetCalendarMonth()*30*24)+(GetCalendarYear()*30*24*12);
|
|
} // fnAbsoluteHour()
|
|
|
|
|
|
int fnGoldValue(object oItem)
|
|
{ // PURPOSE: Return the gold value
|
|
if (GetIsObjectValid(oItem))
|
|
{ // valid item
|
|
if (!GetIdentified(oItem))
|
|
{ // not identified
|
|
SetIdentified(oItem,TRUE);
|
|
int nValue=GetGoldPieceValue(oItem);
|
|
SetIdentified(oItem,FALSE);
|
|
return nValue;
|
|
} // not identified
|
|
else
|
|
{ // return
|
|
return GetGoldPieceValue(oItem);
|
|
} // return
|
|
} // valid item
|
|
return 0;
|
|
} // fnGoldValue()
|
|
|
|
|
|
int fnIsItemCleanable(object oItem,int nThreshold)
|
|
{ // PURPOSE: Return if the item is cleanable
|
|
if (GetPlotFlag(oItem)) return FALSE;
|
|
else if (GetLocalInt(oItem,"bNoClean")) return FALSE;
|
|
else
|
|
{ // test string
|
|
string sTest=GetStringUpperCase(GetStringLeft(GetTag(oItem),4));
|
|
if (sTest=="RTS_") return FALSE;
|
|
else if (fnGoldValue(oItem)>=nThreshold) return FALSE;
|
|
sTest=GetResRef(oItem);
|
|
if (sTest=="MANA_CRYSTAL_5"||sTest=="MANA_CRYSTAL_2"||sTest=="MANA_CRYSTAL_1"||sTest=="rtsa_message") return FALSE;
|
|
} // test string
|
|
return TRUE;
|
|
} // fnIsItemCleanable()
|
|
|
|
|
|
int fnIsPlaceableCleanable(object oPlaceable)
|
|
{ // PURPOSE: Return if okay to destroy this placeable
|
|
if (GetPlotFlag(oPlaceable)) return FALSE;
|
|
else if (!GetHasInventory(oPlaceable)) return FALSE;
|
|
else if (GetLocalInt(oPlaceable,"bNoClean")) return FALSE;
|
|
else
|
|
{ // check tag
|
|
string sTag=GetTag(oPlaceable);
|
|
if (sTag=="wazoo_pl_chest") return FALSE;
|
|
else if (sTag=="unit_inv") return FALSE;
|
|
} // check tag
|
|
return TRUE;
|
|
} // fnIsPlaceableCleanable()
|
|
|
|
|
|
void fnDefaultClean(object oWP,int nThreshold,int nN=1)
|
|
{ // PURPOSE: clean default style
|
|
object oItem=GetNearestObject(OBJECT_TYPE_ITEM,oWP,nN);
|
|
object oContainer=GetNearestObject(OBJECT_TYPE_PLACEABLE,oWP,nN);
|
|
if (GetIsObjectValid(oItem))
|
|
{ // process item
|
|
if (fnIsItemCleanable(oItem,nThreshold))
|
|
{ // clean
|
|
if (GetLocalInt(oItem,"bCleanDecay"))
|
|
{ // decay flag already set - clean
|
|
DelayCommand(3.0,DestroyObject(oItem));
|
|
} // decay flag already set - clean
|
|
else
|
|
{ // set decay flag
|
|
SetLocalInt(oItem,"bCleanDecay",TRUE);
|
|
} // set decay flag
|
|
} // clean
|
|
} // process item
|
|
if (GetIsObjectValid(oContainer))
|
|
{ // process container
|
|
if (fnIsPlaceableCleanable(oContainer))
|
|
{ // clean placeable
|
|
if (GetLocalInt(oContainer,"bCleanDecay"))
|
|
{ // decay flag already set - clean
|
|
DelayCommand(3.0,DestroyObject(oContainer));
|
|
} // decay flag already set - clean
|
|
else
|
|
{ // set decay flag
|
|
SetLocalInt(oContainer,"bCleanDecay",TRUE);
|
|
} // set decay flag
|
|
} // clean placeable
|
|
} // process container
|
|
if (GetIsObjectValid(oItem)||GetIsObjectValid(oContainer)) DelayCommand(0.1,fnDefaultClean(oWP,nThreshold,nN+1));
|
|
} // fnDefaultClean()
|
|
|
|
|
|
void fnAggressiveClean(object oWP,int nThreshold,int nN=1)
|
|
{ // PURPOSE: Aggressive style clean
|
|
object oItem=GetNearestObject(OBJECT_TYPE_ITEM,oWP,nN);
|
|
object oContainer=GetNearestObject(OBJECT_TYPE_PLACEABLE,oWP,nN);
|
|
if (GetIsObjectValid(oItem))
|
|
{ // process item
|
|
if (fnIsItemCleanable(oItem,nThreshold))
|
|
{ // destroy
|
|
DelayCommand(3.0,DestroyObject(oItem));
|
|
} // destroy
|
|
} // process item
|
|
if (GetIsObjectValid(oContainer))
|
|
{ // process container
|
|
if (fnIsPlaceableCleanable(oContainer))
|
|
{ // destroy
|
|
DelayCommand(3.0,DestroyObject(oContainer));
|
|
} // destroy
|
|
} // process container
|
|
if (GetIsObjectValid(oItem)||GetIsObjectValid(oContainer)) DelayCommand(0.1,fnDefaultClean(oWP,nThreshold,nN+1));
|
|
} // fnAggressiveClean()
|
|
|
|
|
|
void main()
|
|
{
|
|
object oMe=OBJECT_SELF;
|
|
if (!GetLocalInt(GetModule(),"nInProgress")) return; // only clean once game is officially started
|
|
object oWP=GetFirstObjectInArea(oMe);
|
|
object oPC=GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR,PLAYER_CHAR_IS_PC,oWP,1);
|
|
if (!GetIsObjectValid(oPC))
|
|
{ // okay to clean
|
|
oWP=GetNearestObject(OBJECT_TYPE_WAYPOINT,oWP);
|
|
if (GetIsObjectValid(oWP))
|
|
{ // waypoint
|
|
object oMod=GetModule();
|
|
int nMode=GetLocalInt(oMod,"nCleanUpMode");
|
|
int nThreshold=GetLocalInt(oMod,"nCleanThreshold");
|
|
if (GetLocalInt(oMe,"nCleanUpMode")>0&&nMode!=2) nMode=GetLocalInt(oMe,"nCleanUpMode");
|
|
if (nMode==2) return;
|
|
if (nThreshold==0) nThreshold=100;
|
|
else if (nThreshold==-1) nThreshold=50;
|
|
else if (nThreshold==-2) nThreshold=20;
|
|
else if (nThreshold==-3) nThreshold=10;
|
|
if (nMode==0)
|
|
{ // default
|
|
int nCurrentHour=fnAbsoluteHour();
|
|
if (!GetLocalInt(oMe,"bCleanHourSet"))
|
|
{ // set
|
|
SetLocalInt(oMe,"bCleanHourSet",TRUE);
|
|
SetLocalInt(oMe,"nCleanHour",nCurrentHour);
|
|
} // set
|
|
else if (nCurrentHour!=GetLocalInt(oMe,"nCleanHour"))
|
|
{ // clean
|
|
int nDelay=d100();
|
|
float fDelay=IntToFloat(nDelay)/20.0;
|
|
DelayCommand(fDelay,fnDefaultClean(oWP,nThreshold));
|
|
SetLocalInt(oMe,"nCleanHour",nCurrentHour);
|
|
} // clean
|
|
} // default
|
|
else
|
|
{ // aggressive
|
|
int nHB=GetLocalInt(oMe,"nCleanHB");
|
|
if (nHB>1)
|
|
{ // clean
|
|
int nDelay=d100();
|
|
float fDelay=IntToFloat(nDelay)/40.0;
|
|
DelayCommand(fDelay,fnAggressiveClean(oWP,nThreshold));
|
|
DeleteLocalInt(oMe,"nCleanHB");
|
|
} // clean
|
|
else
|
|
{ // increment - clean every 3 heartbeats
|
|
SetLocalInt(oMe,"nCleanHB",nHB+1);
|
|
} // increment - clean every 3 heartbeats
|
|
} // aggressive
|
|
} // waypoint
|
|
} // okay to clean
|
|
else
|
|
{ // delete clean hour
|
|
DeleteLocalInt(oMe,"bCleanHourSet");
|
|
} // delete clean hour
|
|
}
|