//:://///////////////////////////////////////////// //:: Name: areascan_inc //:: Copyright (c) 2001 Bioware Corp. //::////////////////////////////////////////////// /* Includefile for managing the area scanner Use together with the conversation "areascanner" */ //::////////////////////////////////////////////// //:: Created By: Flash //:: Created On: 02-mar-2005 //::////////////////////////////////////////////// #include "lod_include" #include "areahandler_inc" #include "areascan_def" void CleanupAreaScanner(); //:://///////////////////////////////////////////// //:: Name: GetASAreaByIndex //:: Created By: Flash //:: Created On: 05-mar-2005 //::////////////////////////////////////////////// object GetASAreaByIndex(int iIndex) { return GetAreaFromLocation(GetLocalLocation(oListOwner, AREASCANNER_AREA_LOC + IntToString(iIndex))); } //:://///////////////////////////////////////////// //:: Name: SetASLocationByIndex //:: Created By: Flash //:: Created On: 06-mar-2005 //::////////////////////////////////////////////// void SetASLocationByIndex(int iIndex, location lInsertLocation) { SetLocalLocation(oListOwner, AREASCANNER_AREA_LOC + IntToString(iIndex), lInsertLocation); } //:://///////////////////////////////////////////// //:: Name: GetASLocationByIndex //:: Created By: Flash //:: Created On: 05-mar-2005 //::////////////////////////////////////////////// location GetASLocationByIndex(int iIndex) { return GetLocalLocation(oListOwner, AREASCANNER_AREA_LOC + IntToString(iIndex)); } //:://///////////////////////////////////////////// //:: Name: SetASSpawnsInAreaByIndex //:: Created By: Flash //:: Created On: 06-mar-2005 //::////////////////////////////////////////////// void SetASSpawnsInAreaByIndex(int iIndex, int iInsertSpawns) { SetLocalInt(oListOwner, AREASCANNER_SPAWNS_IN_AREA + IntToString(iIndex), iInsertSpawns); } //:://///////////////////////////////////////////// //:: Name: GetASSpawnsInAreaByIndex //:: Created By: Flash //:: Created On: 05-mar-2005 //::////////////////////////////////////////////// int GetASSpawnsInAreaByIndex(int iIndex) { return GetLocalInt(oListOwner, AREASCANNER_SPAWNS_IN_AREA + IntToString(iIndex)); } //:://///////////////////////////////////////////// //:: Name: DoMenuCommand //:: Created By: Flash //:: Created On: 05-mar-2005 //::////////////////////////////////////////////// void DoMenuCommand(int iMenuChoise) { location lArea = GetASLocationByIndex(iMenuChoise -1); // Menues start at 1, lists at 0 CleanupAreaScanner(); AssignCommand(oListOwner, ActionJumpToLocation(lArea)); } //:://///////////////////////////////////////////// //:: Name: SetupMenu //:: Created By: Flash //:: Created On: 05-mar-2005 //::////////////////////////////////////////////// int SetupMenu(int iIndex) { int bReturn = FALSE; string sMyString = ""; object oArea = GetASAreaByIndex(iIndex - 1); // Menues starts at 1 list at 0. int iSpawns = GetASSpawnsInAreaByIndex(iIndex - 1); // Menues starts at 1 list at 0. if(GetLocalInt(oListOwner, AREASCANNER_SETUP_OK) && GetIsObjectValid(oArea)) { sMyString = GetName(oArea) + " has : " + IntToString(iSpawns) + " spawns"; SetCustomToken(AREASCANNER_START_CUSTOM_TOKEN + iIndex, sMyString); bReturn = TRUE; } return bReturn; } //:://///////////////////////////////////////////// //:: Name: GetNumberOfSpawnsInArea //:: Created By: Flash //:: Created On: 02-mar-2005 //::////////////////////////////////////////////// int GetNumberOfSpawnsInArea(object oArea) { int iNumberOfSpawns = 0; object oObject = GetFirstObjectInArea(oArea); while (GetIsObjectValid(oObject)) { if (GetIsEncounterCreature(oObject)) iNumberOfSpawns++; oObject = GetNextObjectInArea(oArea); } return iNumberOfSpawns; } //:://///////////////////////////////////////////// //:: Name: InsertASBefore //:: Created By: Flash //:: Created On: 06-mar-2005 //:: Makes room in the list and inserts found location and # of spawns //::////////////////////////////////////////////// void InsertASBefore(int iInsertPosition, location lInsertLocation, int iInsertSpawns) { location lTempLoc; int iTempSpawns; int i; for(i = iCurrentListSize; i >= iInsertPosition; i--) { lTempLoc = GetASLocationByIndex(i); iTempSpawns = GetASSpawnsInAreaByIndex(i); if(i < AREASCANNER_MAX_AREAS) { SetASLocationByIndex(i + 1, lTempLoc); SetASSpawnsInAreaByIndex(i + 1, iTempSpawns); } } SetASLocationByIndex(iInsertPosition, lInsertLocation); SetASSpawnsInAreaByIndex(iInsertPosition, iInsertSpawns); iCurrentListSize = (iCurrentListSize < AREASCANNER_MAX_AREAS) ? iCurrentListSize + 1 : AREASCANNER_MAX_AREAS; } //:://///////////////////////////////////////////// //:: Name: AddAreaToList //:: Created By: Flash //:: Created On: 06-mar-2005 //:: Finds out where in the list the areas should be inserted //::////////////////////////////////////////////// void AddAreaToASList(location lInserLocation, int iInsertSpawns) { int bInserted = FALSE; int i; for(i = 0; ((i <= AREASCANNER_MAX_AREAS) && (i <= iCurrentListSize) && !bInserted); i++) { if(iInsertSpawns > GetASSpawnsInAreaByIndex(i)) { InsertASBefore(i, lInserLocation, iInsertSpawns); bInserted = TRUE; } } } //:://///////////////////////////////////////////// //:: Name: ScanAreasForOverfarming //:: Created By: Flash //:: Created On: 06-mar-2005 //::////////////////////////////////////////////// void ScanAreasForOverfarming() { int i; int iNumberOfOverfarmedAreas = 0; int iSpawns; location lArea; for(i = 0; i <= GetAreaCount(); i++) { lArea = GetAreaLocationByIndex(i); iSpawns = GetNumberOfSpawnsInArea(GetAreaFromLocation(lArea)); if(iSpawns > AREASCANNER_MAX_SPAWNS_IN_AREAS) { AddAreaToASList(lArea, iSpawns); iNumberOfOverfarmedAreas++; } } SetLocalInt(oListOwner, AREASCANNER_AREA_COUNT, iNumberOfOverfarmedAreas); } //:://///////////////////////////////////////////// //:: Name: SearchAndDestroy //:: Created By: Flash //:: Created On: 14-mar-2005 //::////////////////////////////////////////////// void SearchAndDestroy() { int i, iDestroyedSpawns, iSpawns; object oArea, oObject; for(i = 0; i <= GetAreaCount(); i++) { oArea = GetAreaByIndex(i); iSpawns = GetNumberOfSpawnsInArea(oArea); if(iSpawns > AREASCANNER_MAX_SPAWNS_IN_AREAS) { iDestroyedSpawns = 0; oObject = GetFirstObjectInArea(oArea); SendMessageToAllDMs(GetName(oArea) + " has too many spawns."); while (GetIsObjectValid(oObject)) { if (GetIsPC(oObject)) SendMessageToAllDMs(GetName(oObject)); if (GetIsEncounterCreature(oObject) && !IsLoDBoss(oObject) && (iDestroyedSpawns < iSpawns - AREASCANNER_MAX_SPAWNS_IN_AREAS)) { DestroyObject(oObject); iDestroyedSpawns++; } oObject = GetNextObjectInArea(oArea); } SendMessageToAllDMs(IntToString(iDestroyedSpawns) + " spawns destroyed."); } } } //:://///////////////////////////////////////////// //:: Name: CleanupAreaScanner //::////////////////////////////////////////////// /* Deletes all local variables on oListOwner */ //::////////////////////////////////////////////// //:: Created By: Flash //:: Created On: 02-mar-2005 //::////////////////////////////////////////////// void CleanupAreaScanner() { int i; for(i = 0; i <= AREASCANNER_MAX_AREAS; i++) { DeleteLocalLocation(oListOwner, AREASCANNER_AREA_LOC + IntToString(i)); DeleteLocalInt(oListOwner, AREASCANNER_SPAWNS_IN_AREA+ IntToString(i)); } DeleteLocalInt(oListOwner, AREASCANNER_AREA_COUNT); DeleteLocalInt(oListOwner, AREASCANNER_SETUP_OK); iCurrentListSize = 0; } //:://///////////////////////////////////////////// //:: Name: SetupAreaScanner //::////////////////////////////////////////////// /* Called from script defined in modules OnActivateItem wich should also activate the conversation "areascanner". */ //::////////////////////////////////////////////// //:: Created By: Flash //:: Created On: 02-mar-2005 //::////////////////////////////////////////////// int SetupAreaScanner(object oSpeaker) { int bSetupOK = FALSE; oListOwner = oSpeaker; object oArea = GetFirstArea(); if(GetIsObjectValid(oArea)) { ScanAreasForOverfarming(); bSetupOK = TRUE; } SetLocalInt(oListOwner, AREASCANNER_SETUP_OK, bSetupOK); return bSetupOK; }