View Single Post
  #7  
Old 11-09-2012, 06:34 AM
c0ncrete's Avatar
c0ncrete
Dragon
 
Join Date: Dec 2009
Posts: 719
Default

yeah, i guess the OOCRegen rule would probably be easier. i keep forgetting to familiarize myself with the various rules... :|

i'm a bit confused about what i'm reading in the source about the loading of npc quest files, however. i come up with this order from reading PerlembParser::LoadScript() in zone/embparser.cpp

1) quests/default.pl
2) quests/<zone>/<npcid>.pl
3) quests/<zone>/<npcname>.pl
4) quests/templates/<npcname>.pl
5) quests/templates/<npcid>.pl
6) quests/<zone>/default.pl
7) quests/templates/default.pl

this is what i'm looking at to come to this conclusion:

Code:
int PerlembParser::LoadScript(int npcid, const char * zone, Mob* activater)
{
	if(!perl)
	{
		return(0);
	}

	//we have already tried to load this quest...
	if(hasQuests.count(npcid) == 1)
	{
		return(1);
	}

	string filename = "quests/", packagename = GetPkgPrefix(npcid);
	//each package name is of the form qstxxxx where xxxx = npcid (since numbers alone are not valid package names)
	questMode curmode = questDefault;
	FILE *tmpf;
	//LogFile->write(EQEMuLog::Debug, "LoadScript(%d, %s):\n", npcid, zone);
	if(!npcid || !zone)
	{
		//Load quests/default.pl
		filename += DEFAULT_QUEST_PREFIX;
		filename += ".pl";
		curmode = questDefault;
	}
	else
	{
		filename += zone;
		filename += "/";
#ifdef QUEST_SCRIPTS_BYNAME
		string bnfilename = filename;
#endif
		filename += itoa(npcid);
		filename += ".pl";
		curmode = questByID;

#ifdef QUEST_SCRIPTS_BYNAME
		//assuming name limit stays 64 chars.
		char tmpname[64];
		int count0 = 0;
		bool filefound = false;
		tmpf = fopen(filename.c_str(), "r");
		if(tmpf != NULL)
		{
			fclose(tmpf);
			filefound = true;
		}
		//LogFile->write(EQEMuLog::Debug, "	tried '%s': %d", filename.c_str(), filefound);

		tmpname[0] = 0;
		//if there is no file for the NPC's ID, try for the NPC's name
		if(!filefound)
		{
			//revert to just path
			filename = bnfilename;
			const NPCType *npct = database.GetNPCType(npcid);
			if(npct == NULL)
			{
				//LogFile->write(EQEMuLog::Debug, "	no npc type");
				//revert and go on with life
				filename += itoa(npcid);
				filename += ".pl";
				curmode = questByID;
			}
			else
			{
				//trace out the ` characters, turn into -
				int nlen = strlen(npct->name);
				//just to make sure
				if(nlen < 64)
				{
					int r;
					//this should get our NULL as well..
					for(r = 0; r <= nlen; r++)
					{
						tmpname[r] = npct->name[r];

						//watch for 00 delimiter
						if(tmpname[r] == '0')
						{
							count0++;
							//second '0'
							if(count0 > 1)
							{
								//stop before previous 0
								tmpname[r-1] = '\0';
								break;
							}
						}
						else
						{
							count0 = 0;
						}

						//rewrite ` to be more file name friendly
						if(tmpname[r] == '`')
						{
							tmpname[r] = '-';
						}

					}
					filename += tmpname;
					filename += ".pl";
					curmode = questByName;
				}
				else
				{
					//LogFile->write(EQEMuLog::Debug, "	namelen too long");
					//revert and go on with life, again
					filename += itoa(npcid);
					filename += ".pl";
					curmode = questByID;
				}
			}
		}

#ifdef QUEST_TEMPLATES_BYNAME

		tmpf = fopen(filename.c_str(), "r");
		if(tmpf != NULL)
		{
			fclose(tmpf);
			filefound = true;
		}


		//LogFile->write(EQEMuLog::Debug, "	tried '%s': %d", filename.c_str(), filefound2);

		//if there is no file for the NPC's ID or name,
		//try for the NPC's name in the templates directory
		//only works if we have gotten the NPC's name above
		if(!filefound)
		{
			if(tmpname[0] != 0)
			{
				//revert to just path
				filename = "quests/";
				filename += QUEST_TEMPLATES_DIRECTORY;
				filename += "/";
				filename += tmpname;
				filename += ".pl";
				curmode = questTemplate;
				//LogFile->write(EQEMuLog::Debug, "	template '%s'", filename.c_str(), filefound2);
			}
			else
			{
				//LogFile->write(EQEMuLog::Debug, "	no template name");
				filename = "quests/";
				filename += QUEST_TEMPLATES_DIRECTORY;
				filename += "/";
				filename += itoa(npcid);
				filename += ".pl";
				curmode = questTemplateByID;
			}
		}
		
#endif	//QUEST_TEMPLATES_BYNAME

#endif //QUEST_SCRIPTS_BYNAME

		tmpf = fopen(filename.c_str(), "r");
		if(tmpf != NULL)
		{
			fclose(tmpf);
			filefound = true;
		}
		
		// If by ID, Name or Template wasn't found, load /quests/zone/default.pl
		if(!filefound)
		{
			//Load Default Quests Per Zone quests/zonename/default.pl
			filename = bnfilename;
			filename += "default.pl";
			curmode = questDefaultByZone;
			//LogFile->write(EQEMuLog::Debug, "LoadScript(%s)", filename.c_str());
		}

		tmpf = fopen(filename.c_str(), "r");
		if(tmpf != NULL)
		{
			fclose(tmpf);
			filefound = true;
		}
		
		// If zone template isn't found look for it globally /quests/template/default.pl
		if(!filefound)
		{
			//Load Default Quests Globally
			//filename = bnfilename;
			filename = "quests/";
			filename += QUEST_TEMPLATES_DIRECTORY;
			filename += "/";
			filename += "default.pl";
			curmode = questDefaultByZone;
			//LogFile->write(EQEMuLog::Debug, "LoadScript(%s)", filename.c_str());
		}
	}
am i just not reading/understanding something correctly?

EDIT:
i may have just answered my own question. it's only looking for quests/default.pl if no npcid or zoneid are supplied. i haven't looked at where this is called from, but i'm guessing it's probably pretty rare for that to occur.

Last edited by c0ncrete; 11-09-2012 at 06:38 AM.. Reason: duh...
Reply With Quote