View Single Post
  #2  
Old 02-16-2014, 06:40 PM
DrakePhoenix
Fire Beetle
 
Join Date: Jan 2014
Posts: 22
Default

OK, first let's talk about setting things up so that the #bot spawn command can accept optional texture and helmtexture variables. Once we have that done, then we'll talk about how to make the system actually use those variables when provided, and choose appropriate defaults for them when the are not provided.

Navigate through the bot.cpp file to the "Bot::ProcessBotCommands(Client *c, const Seperator *sep)" function again. This time we're going to the section for bot spawning, instead of bot creation, so search for the line that starts "if(!strcasecmp(sep->arg[1], "spawn") )". This is where the #bot spawn command is parsed and processed.

Right at the top of this code segment you'll find a line that reads "uint32 botId = GetBotIDByBotName(std::string(sep->arg[2]));". Immediately below that line, add in the following...
Code:
		uint8 textureparam = 0;
		uint8 helmtextureparam = 0;
Now, continue on through this section, past all the potential spawn failure checks, to where you find the line "Bot* TempBot = LoadBot(botId, &TempErrorMessage)". This is the point where the bot object is loaded into the system, but it is not yet spawned and made visible in the zone. The system then checks if the LoadBot function failed in some way, but if it didn't and we have successfully loaded a bot object into the system, then the command processing continues on to do a few other quick changes to the bot object, and then to spawn the bot into the zone.

Now, *INSIDE* the if(TempBot) if statement code section, and *above* the "TempBot->Spawn(c, &TempErrorMessage);" function call, enter the following (comments are optional)...
Code:
			// DrakePhoenix:  need to establlish textureparam and helmtextureparam default values based on race...
			// default values are set to 0 above, but provided values can also be 0
			// if nonstandard race, we want default of 0 if not provided, but if provided, we want to use what was provided (including 0, if that is the case)
			// if standard race, then we want default of 255 if not provided, else use provided value (including 0 or 255, if that is the case)
			uint16 race = TempBot->GetRace(); // get the bot's race so that we can use it to check if it is a standard race or a non-standard one
			if(sep->arg[3][0] != '\0') // check for texture parameter, and if it exists do the following...
			{
				textureparam = uint8(atoi(sep->arg[3])); // get the texture parameter, convert from string to int, convert to uint8, and set textureparam variable to equal the resulting value
			}
			else if((race > 12) && (race != 128) && (race != 130) && (race != 330) && (race != 522)) // if no texture parameter provided, and if non-standard race, set value to default 0
			{
				textureparam = 0;
			}
			else // if no texture parameter provided and standard race, set value to default 255.
			{
				textureparam = 0xFF;
			}

			if(sep->arg[4][0] != '\0') // check for helmtexture parameter, and if it exists do the following...
			{
				helmtextureparam = uint8(atoi(sep->arg[4])); // get the helmtexture parameter, convert from string to int, convert to uint8, and set textureparam variable to equal the resulting value
			}
			else if((race > 12) && (race != 128) && (race != 130) && (race != 330) && (race != 522)) // if no helmtexture parameter provided, and if non-standard race, set value to default 0
			{
				helmtextureparam = 0;
			}
			else // if no helmtexture parameter provided and standard race, set value to default 255.
			{
				helmtextureparam = 0xFF;
			}
So now we have told the system how to determine what values to use for the texture and helmtexture paramaters that we will be working with, including default values if the parameters were not included in the #bot spawn command that the player used.


Now we need to change the "Bot::Spawn(Client* botCharacterOwner, std::string* errorMessage)" command to actually accept the additional parameters of texture and helmtexture. And we will also need to change how the function works so that it actually uses those parameters once they are in place.

So first, open up the bot.h header file, because we need to change the function declaration for the Spawn function. In the bot.h file, navigate to the Spawn function declaration. Should read as "void Spawn(Client* botCharacterOwner, std::string* errorMessage);". Change it to read as "void Spawn(Client* botCharacterOwner, std::string* errorMessage, uint8 textureparam, uint8 helmtextureparam);" instead. This tells the system that this function now requires 4 parameters instead of just 2.

Now go back to bot.cpp and the #bot spawn command processing section. Find the line for "TempBot->Spawn(c, &TempErrorMessage);" and change it to "TempBot->Spawn(c, &TempErrorMessage, textureparam, helmtextureparam);" instead. Remember that we already changed an earlier part of this code section to create the variables of textureparam and helmtextureparam that are being used here.

We also need to change every other instance that this function is called to make it use 4 paramaters, instead of the original 2. If you're working visual studio you can simply right-click on "Spawn" in the function call and then click on Find All References to search through every location in the code. But I'm going to walk you through them anyway, because it isn't as simple as just changing the function calls, you have also create the parameter variables that will be used.

So the next place to do this is in the "Bot::LoadAndSpawnAllZonedBots(Client* botOwner)" function. Go to that function, then find the line that reads "activeBot->Spawn(botOwner, &errorMessage);". We need to change this function call, and we need to make the variables for textureparam and helmtextureparam. Since this function is for active bots that already exist, we want to get the parameters from the existing bot object. Change the code to the following...
Code:
							uint8 textureparam = activeBot->GetTexture();
							uint8 helmtextureparam = activeBot->GetHelmTexture();
							activeBot->Spawn(botOwner, &errorMessage, textureparam, helmtextureparam);
Then the next two places we need to change this are deep inside the bot command processing function. First, look for the line that reads "botGroupLeader->Spawn(c, &TempErrorMessage);". We need to add the variables here, as well as the modifying the function call, so enter the following...
Code:
		uint8 textureparam = botGroupLeader->GetTexture();
		uint8 helmtextureparam = botGroupLeader->GetHelmTexture();
		botGroupLeader->Spawn(c, &TempErrorMessage,  textureparam, helmtextureparam);
Then, about 35-40 code lines later you should find another line that reads "botGroupMember->Spawn(c, &TempErrorMessage);". We need the variables again, as well as the change to the function call. So, for the botGroupMember line, enter the following in its place...
Code:
			uint8 textureparam = botGroupMember->GetTexture();
			uint8 helmtextureparam = botGroupMember->GetHelmTexture();
			botGroupMember->Spawn(c, &TempErrorMessage, textureparam, helmtextureparam);
Now it's time to edit the "Bot::Spawn(Client* botCharacterOwner, std::string* errorMessage)" function itself. This is where the rest of the work takes place...
Reply With Quote