mirror of
https://github.com/UOX3DevTeam/UOX3
synced 2026-08-13 12:27:04 -04:00
Misc code and documentation cleanup: Updated and standardized function comment blocks throughout entire codebase Grouped getters and setters together in pairs and documented them as one Removed empty and/or non-useful information from comment blocks Removed unused function from cItem.cpp/h - IncID() - formerly used to change IDs for doors Added new feature - Instances Objects (characters, items, multis, spawnregions) can now make use of a 5th parameter to determine their location in the game world. In addition to the traditional X, Y, Z and WORLDNUMBER parameters, a new one has been added - INSTANCEID - that allows objects to exist at the same coordinates in the same world, but in different "dimensions". Code has been updated in multiple places to support this, and a default instanceID of 0 is assumed if nothing else is specified. Added support for new DFN tag in town regions, spawn regions and locations - INSTANCEID (defaults to 0 if not present) Added support for another start location parameter after worldNum in UOX.INI representing instanceID (defaults to 0 if not present) Updated TWEAK menu to include WorldNumber and instanceID Fixed BaseWeight option in TWEAK menu Updated CBase_Teleport - now takes an optional 5th parameter instanceID Updated SE_SpawnNPC now takes an optional 5th parameter - instanceID Updated SE_FindMulti now takes an optional 5th parameter - instanceID Updated SE_GetItem now takes an optional 5th parameter - instanceID Updated SE_FindItem now takes an optional 6th parameter - instanceID Added new JS property for Items, Characters, Regions: .instanceID Added JS property for Regions: .members - returns comma-separated list of town member serials Updated JS scripts making use of the above-mentioned JS Methods/Functions Updated dictionaries with new tweak menu entry texts Exposed SpawnRegions to JS engine, and updated JS docs with details: SpawnRegion JS Functions IterateOverSpawnRegions() GetSpawnRegion( spawnRegNum ) GetSpawnRegionCount() SpawnRegion JS Properties name regionNum itemList npcList item npc maxItems maxNpcs itemCount npcCount onlyOutside prefZ x1 y1 x2 y2 world instanceID minTime maxTime call
236 lines
9.1 KiB
C++
236 lines
9.1 KiB
C++
//
|
|
// Cache script section locations by <erwin@andreasen.com>
|
|
// Reads through the contents of the file and saves location of each
|
|
// SECTION XYZ entry
|
|
|
|
// Calling Script::find() will then seek to that location directly rather
|
|
// than having to parse through all of the script
|
|
//
|
|
#include "uox3.h"
|
|
#include "ssection.h"
|
|
#include "scriptc.h"
|
|
|
|
#undef DBGFILE
|
|
#define DBGFILE "scriptc.cpp"
|
|
|
|
namespace UOX
|
|
{
|
|
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Function - bool get_modification_date( const std::string& filename, time_t* mod_time )
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Purpose - Returns true if the file's stats can be found (testing its existence)
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
bool get_modification_date( const std::string& filename, time_t* mod_time )
|
|
{
|
|
struct stat stat_buf;
|
|
|
|
if( stat( filename.c_str(), &stat_buf ) )
|
|
return false;
|
|
|
|
*mod_time = stat_buf.st_mtime;
|
|
return true;
|
|
}
|
|
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Function - void reload( bool disp )
|
|
//| Programmer - Abaddon
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Purpose - Reload's the scripts data. If disp is true, then information is output to
|
|
//| the console (# of sections). Will not run if the script is in an erroneous state
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
void Script::reload( bool disp )
|
|
{
|
|
if( !errorState )
|
|
{
|
|
// Clear the map, we are starting from scratch;
|
|
deleteMap();
|
|
char line[2048];
|
|
input.open( filename.c_str(), std::ios_base::in );
|
|
if( input.is_open() )
|
|
{
|
|
UString sLine;
|
|
SI32 count = 0;
|
|
while( !input.eof() && !input.fail() )
|
|
{
|
|
input.getline( line, 2048 );
|
|
sLine = line;
|
|
sLine = sLine.removeComment().stripWhiteSpace();
|
|
if( !sLine.empty() )
|
|
{
|
|
// We have some real data
|
|
// see if in a section
|
|
if( sLine.substr( 0, 1 ) == "[" && sLine.substr( sLine.size() - 1 ) == "]" )
|
|
{
|
|
// Ok a section is starting here, get the name
|
|
UString sectionname = sLine.substr( 1, sLine.size() - 2 );
|
|
sectionname = sectionname.simplifyWhiteSpace().upper();
|
|
// Now why we look for a {, no idea, but we do - Because we want to make sure that were IN a block not before the block. At least this makes sure that were inside the {}'s of a block...
|
|
while( !input.eof() && sLine.substr( 0, 1 ) != "{" && !input.fail() )
|
|
{
|
|
input.getline( line, 2048 );
|
|
sLine = line;
|
|
sLine = sLine.removeComment().stripWhiteSpace();
|
|
}
|
|
// We are finally in the actual section!
|
|
// We waited until now to create it, incase a total invalid file
|
|
lastModTime = 0;
|
|
defEntries[sectionname] = new ScriptSection( input, dfnCat );
|
|
++count;
|
|
}
|
|
}
|
|
}
|
|
input.close();
|
|
}
|
|
else
|
|
{
|
|
fprintf( stderr, "Cannot open %s: %s", filename.c_str(), strerror( errno ) );
|
|
errorState = true;
|
|
}
|
|
}
|
|
if( disp )
|
|
Console.Print( "Reloading %-15s: ", filename.c_str() );
|
|
|
|
fflush( stdout );
|
|
}
|
|
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Function - Script( const std::string& _filename, DEFINITIONCATEGORIES d, bool disp ) : errorState( false ), dfnCat( d )
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Purpose - Builds the script, reading in the information from the script file.
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
Script::Script( const std::string& _filename, DEFINITIONCATEGORIES d, bool disp ) : errorState( false ), dfnCat( d )
|
|
{
|
|
filename = _filename;
|
|
if( !get_modification_date( filename, &last_modification ) )
|
|
{
|
|
fprintf( stderr, "Cannot open %s: %s", filename.c_str(), strerror( errno ) );
|
|
errorState = true;
|
|
}
|
|
reload( disp );
|
|
}
|
|
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Function - ~Script()
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Purpose - Destroys any memory that has been allocated
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
Script::~Script()
|
|
{
|
|
deleteMap();
|
|
}
|
|
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Function - bool isin( const std::string& section )
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Purpose - Returns true if the section named section is in the script
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
bool Script::isin( const std::string& section )
|
|
{
|
|
UString temp( section );
|
|
SSMAP::const_iterator iSearch = defEntries.find( temp.upper() );
|
|
if( iSearch != defEntries.end() )
|
|
return true;
|
|
return false;
|
|
}
|
|
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Function - ScriptSection *FindEntry( const std::string& section )
|
|
//| Programmer - Abaddon
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Purpose - Returns a ScriptSection * to the section named "section"
|
|
//| if it exists, otherwise returning NULL
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
ScriptSection *Script::FindEntry( const std::string& section )
|
|
{
|
|
ScriptSection *rvalue = NULL;
|
|
SSMAP::const_iterator iSearch = defEntries.find( section );
|
|
if( iSearch != defEntries.end() )
|
|
rvalue = iSearch->second;
|
|
return rvalue;
|
|
}
|
|
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Function - ScriptSection *FindEntrySubStr( const std::string& section )
|
|
//| Programmer - Abaddon
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Purpose - Find the first ScriptSection * (if any) that has the
|
|
//| string section in the section name
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
ScriptSection *Script::FindEntrySubStr( const std::string& section )
|
|
{
|
|
ScriptSection *rvalue = NULL;
|
|
UString usection( section );
|
|
usection = usection.upper();
|
|
for( SSMAP::const_iterator iSearch = defEntries.begin(); iSearch != defEntries.end(); ++iSearch )
|
|
{
|
|
if( iSearch->first.find( usection ) != std::string::npos ) // FOUND IT!
|
|
{
|
|
rvalue = iSearch->second;
|
|
break;
|
|
}
|
|
}
|
|
return rvalue;
|
|
}
|
|
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Function - ScriptSection *FirstEntry( void )
|
|
//| Programmer - Abaddon
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Purpose - Returns the first ScriptSection in the Script (if any)
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
ScriptSection *Script::FirstEntry( void )
|
|
{
|
|
ScriptSection *rvalue = NULL;
|
|
iSearch = defEntries.begin();
|
|
if( iSearch != defEntries.end() )
|
|
rvalue = iSearch->second;
|
|
return rvalue;
|
|
}
|
|
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Function - ScriptSection *NextEntry( void )
|
|
//| Programmer - Abaddon
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Purpose - Returns the next ScriptSection (if any) in the Script
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
ScriptSection *Script::NextEntry( void )
|
|
{
|
|
ScriptSection *rvalue = NULL;
|
|
if( iSearch != defEntries.end() )
|
|
{
|
|
++iSearch;
|
|
if( iSearch != defEntries.end() )
|
|
rvalue = iSearch->second;
|
|
}
|
|
return rvalue;
|
|
}
|
|
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Function - deleteMap( void )
|
|
//| Programmer - Abaddon
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Purpose - Destroys any memory that has been allocated
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
void Script::deleteMap( void )
|
|
{
|
|
for( SSMAP::const_iterator iTest = defEntries.begin(); iTest != defEntries.end(); ++iTest )
|
|
delete iTest->second;
|
|
defEntries.clear();
|
|
}
|
|
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Function - std::string EntryName( void )
|
|
//| Programmer - Abaddon
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
//| Purpose - Returns the section name for the current entry (if any)
|
|
//o-----------------------------------------------------------------------------------------------o
|
|
std::string Script::EntryName( void )
|
|
{
|
|
std::string rvalue;
|
|
if( iSearch != defEntries.end() )
|
|
rvalue = iSearch->first;
|
|
return rvalue;
|
|
}
|
|
|
|
}
|