I need help with a problem from someone with more C++ exp.
I have some code that I just can't put the final cap on.
Here it is:
This code is in Bot::FillSpawnStruct
Code:
//CRIIMSON: Get BotID
uint32 spawnedbotid = 0;
spawnedbotid = this->GetBotID();
Say("BotID = %i", spawnedbotid);
inst = GetBotItem(SLOT_HANDS);
if(inst) {
item = inst->GetItem();
if(item) {
ns->spawn.equipment[MATERIAL_HANDS] = item->Material;
ns->spawn.colors[MATERIAL_HANDS].color = Bot::GetEquipmentColor(MATERIAL_HANDS, spawnedbotid);
Say("Hands color = %i and spawnedbotid = %i", Bot::GetEquipmentColor(MATERIAL_HANDS, spawnedbotid), spawnedbotid);
}
}
There are more calls, but they all are similar.
And this gets called
Code:
uint32 Bot::GetEquipmentColor(int8 material_slot, uint32 botid) const
{
//CRIIMSON: Bot tints
int32 slotid = 0;
uint32 returncolor = 0;
//Translate code slot # to DB slot #
while(slotid == 0){
if (material_slot == 0){
slotid = 2;
}
else if (material_slot == 1){
slotid = 17;
}
else if (material_slot == 2){
slotid = 7;
}
else if (material_slot == 3){
slotid = 9;
}
else if (material_slot == 4){
slotid = 12;
}
else if (material_slot == 5){
slotid = 18;
}
else if (material_slot == 6){
slotid = 19;
}
//CRIIMSON: next two won't be called usually - put in for servers that want to allow dying of weaps/shields
else if (material_slot == 7){
slotid = 13;
}
else if (material_slot == 8){
slotid = 14;
}
}
//CRIIMSON: read from db
char* Query = 0;
MYSQL_RES* DatasetResult;
MYSQL_ROW DataRow;
if(database.RunQuery(Query, MakeAnyLenString(&Query, "SELECT color FROM botinventory WHERE BotID = %i AND SlotID = %i", botid, slotid), 0, &DatasetResult)) {
if(mysql_num_rows(DatasetResult) == 1) {
DataRow = mysql_fetch_row(DatasetResult);
if(DataRow)
returncolor = atoi(DataRow[0]);
}
mysql_free_result(DatasetResult);
safe_delete_array(Query);
}
return returncolor;
}
Now the problem is a catch 22.
If I remove the const on Bot::GetEquipmentColor (as it is above) the color value is transfered but it doesnt show in game
If I leave it a const I cant put a pointer in the function to check botid (because the ID can change) so I tried to add the second variable sent to it. This sends and retieves the correct info from db but again it doesnt show in game.
Which is weird because the slotid changes fine even when defined as a const
I know the function called like:
uint32 Bot::GetEquipmentColor(int8 material_slot) const
will change all of the colors of armor (and shows in game) if I set the return as a number like 1644825 (which is black). However, this wont allow a botid variable which is neccessary to get the correct bots color scheme.
The only way I get it to work is not sending botid or having a pointer in the const to botid.
going friggin crazy over this.
So close I can taste it.
Criimson