Some clang-formatting

This commit is contained in:
Michael Cook (mackal) 2015-01-31 00:00:02 -05:00
parent a18cb6f61e
commit 0f1b504ed6

View File

@ -477,16 +477,20 @@ bool SharedDatabase::GetSharedBank(uint32 id, Inventory* inv, bool is_charid) {
return true; return true;
} }
// Overloaded: Retrieve character inventory based on character id // Overloaded: Retrieve character inventory based on character id
bool SharedDatabase::GetInventory(uint32 char_id, Inventory* inv) { bool SharedDatabase::GetInventory(uint32 char_id, Inventory *inv)
{
// Retrieve character inventory // Retrieve character inventory
std::string query = StringFormat("SELECT slotid, itemid, charges, color, augslot1, " std::string query =
"augslot2, augslot3, augslot4, augslot5, augslot6, instnodrop, custom_data, ornamenticon, ornamentidfile, ornament_hero_model " StringFormat("SELECT slotid, itemid, charges, color, augslot1, augslot2, augslot3, augslot4, augslot5, "
"FROM inventory WHERE charid = %i ORDER BY slotid", char_id); "augslot6, instnodrop, custom_data, ornamenticon, ornamentidfile, ornament_hero_model FROM "
"inventory WHERE charid = %i ORDER BY slotid",
char_id);
auto results = QueryDatabase(query); auto results = QueryDatabase(query);
if (!results.Success()) { if (!results.Success()) {
Log.Out(Logs::General, Logs::Error, "If you got an error related to the 'instnodrop' field, run the following SQL Queries:\nalter table inventory add instnodrop tinyint(1) unsigned default 0 not null;\n"); Log.Out(Logs::General, Logs::Error, "If you got an error related to the 'instnodrop' field, run the "
"following SQL Queries:\nalter table inventory add instnodrop "
"tinyint(1) unsigned default 0 not null;\n");
return false; return false;
} }
@ -505,35 +509,37 @@ bool SharedDatabase::GetInventory(uint32 char_id, Inventory* inv) {
aug[4] = (uint32)atoul(row[8]); aug[4] = (uint32)atoul(row[8]);
aug[5] = (uint32)atoul(row[9]); aug[5] = (uint32)atoul(row[9]);
bool instnodrop = (row[10] && (uint16)atoi(row[10]))? true: false; bool instnodrop = (row[10] && (uint16)atoi(row[10])) ? true : false;
uint32 ornament_icon = (uint32)atoul(row[12]); uint32 ornament_icon = (uint32)atoul(row[12]);
uint32 ornament_idfile = (uint32)atoul(row[13]); uint32 ornament_idfile = (uint32)atoul(row[13]);
uint32 ornament_hero_model = (uint32)atoul(row[14]); uint32 ornament_hero_model = (uint32)atoul(row[14]);
const Item_Struct* item = GetItem(item_id); const Item_Struct *item = GetItem(item_id);
if (!item) { if (!item) {
Log.Out(Logs::General, Logs::Error,"Warning: charid %i has an invalid item_id %i in inventory slot %i", char_id, item_id, slot_id); Log.Out(Logs::General, Logs::Error,
"Warning: charid %i has an invalid item_id %i in inventory slot %i", char_id, item_id,
slot_id);
continue; continue;
} }
int16 put_slot_id = INVALID_INDEX; int16 put_slot_id = INVALID_INDEX;
ItemInst* inst = CreateBaseItem(item, charges); ItemInst *inst = CreateBaseItem(item, charges);
if (inst == nullptr) if (inst == nullptr)
continue; continue;
if(row[11]) { if (row[11]) {
std::string data_str(row[11]); std::string data_str(row[11]);
std::string idAsString; std::string idAsString;
std::string value; std::string value;
bool use_id = true; bool use_id = true;
for(int i = 0; i < data_str.length(); ++i) { for (int i = 0; i < data_str.length(); ++i) {
if(data_str[i] == '^') { if (data_str[i] == '^') {
if(!use_id) { if (!use_id) {
inst->SetCustomData(idAsString, value); inst->SetCustomData(idAsString, value);
idAsString.clear(); idAsString.clear();
value.clear(); value.clear();
@ -544,7 +550,7 @@ bool SharedDatabase::GetInventory(uint32 char_id, Inventory* inv) {
} }
char v = data_str[i]; char v = data_str[i];
if(use_id) if (use_id)
idAsString.push_back(v); idAsString.push_back(v);
else else
value.push_back(v); value.push_back(v);
@ -555,15 +561,19 @@ bool SharedDatabase::GetInventory(uint32 char_id, Inventory* inv) {
inst->SetOrnamentationIDFile(ornament_idfile); inst->SetOrnamentationIDFile(ornament_idfile);
inst->SetOrnamentHeroModel(ornament_hero_model); inst->SetOrnamentHeroModel(ornament_hero_model);
if (instnodrop || (((slot_id >= EmuConstants::EQUIPMENT_BEGIN && slot_id <= EmuConstants::EQUIPMENT_END) || slot_id == MainPowerSource) && inst->GetItem()->Attuneable)) if (instnodrop ||
(((slot_id >= EmuConstants::EQUIPMENT_BEGIN && slot_id <= EmuConstants::EQUIPMENT_END) ||
slot_id == MainPowerSource) &&
inst->GetItem()->Attuneable))
inst->SetAttuned(true); inst->SetAttuned(true);
if (color > 0) if (color > 0)
inst->SetColor(color); inst->SetColor(color);
if(charges==0x7FFF) if (charges == 0x7FFF)
inst->SetCharges(-1); inst->SetCharges(-1);
else if (charges == 0 && inst->IsStackable()) // Stackable items need a minimum charge of 1 remain moveable. else if (charges == 0 &&
inst->IsStackable()) // Stackable items need a minimum charge of 1 remain moveable.
inst->SetCharges(1); inst->SetCharges(1);
else else
inst->SetCharges(charges); inst->SetCharges(charges);
@ -575,18 +585,15 @@ bool SharedDatabase::GetInventory(uint32 char_id, Inventory* inv) {
} }
} }
if (slot_id >= 8000 && slot_id <= 8999) if (slot_id >= 8000 && slot_id <= 8999) {
{
put_slot_id = inv->PushCursor(*inst); put_slot_id = inv->PushCursor(*inst);
} } else if (slot_id >= 3111 && slot_id <= 3179) {
else if (slot_id >= 3111 && slot_id <= 3179)
{
// Admins: please report any occurrences of this error // Admins: please report any occurrences of this error
Log.Out(Logs::General, Logs::Error, "Warning: Defunct location for item in inventory: charid=%i, item_id=%i, slot_id=%i .. pushing to cursor...", char_id, item_id, slot_id); Log.Out(Logs::General, Logs::Error, "Warning: Defunct location for item in inventory: "
"charid=%i, item_id=%i, slot_id=%i .. pushing to cursor...",
char_id, item_id, slot_id);
put_slot_id = inv->PushCursor(*inst); put_slot_id = inv->PushCursor(*inst);
} } else {
else
{
put_slot_id = inv->PutItem(slot_id, *inst); put_slot_id = inv->PutItem(slot_id, *inst);
} }
@ -594,7 +601,9 @@ bool SharedDatabase::GetInventory(uint32 char_id, Inventory* inv) {
// Save ptr to item in inventory // Save ptr to item in inventory
if (put_slot_id == INVALID_INDEX) { if (put_slot_id == INVALID_INDEX) {
Log.Out(Logs::General, Logs::Error, "Warning: Invalid slot_id for item in inventory: charid=%i, item_id=%i, slot_id=%i",char_id, item_id, slot_id); Log.Out(Logs::General, Logs::Error,
"Warning: Invalid slot_id for item in inventory: charid=%i, item_id=%i, slot_id=%i",
char_id, item_id, slot_id);
} }
} }
@ -603,20 +612,24 @@ bool SharedDatabase::GetInventory(uint32 char_id, Inventory* inv) {
} }
// Overloaded: Retrieve character inventory based on account_id and character name // Overloaded: Retrieve character inventory based on account_id and character name
bool SharedDatabase::GetInventory(uint32 account_id, char* name, Inventory* inv) { bool SharedDatabase::GetInventory(uint32 account_id, char *name, Inventory *inv)
{
// Retrieve character inventory // Retrieve character inventory
std::string query = StringFormat("SELECT slotid, itemid, charges, color, augslot1, " std::string query =
"augslot2, augslot3, augslot4, augslot5, augslot6, instnodrop, custom_data, ornamenticon, ornamentidfile, ornament_hero_model " StringFormat("SELECT slotid, itemid, charges, color, augslot1, "
"augslot2, augslot3, augslot4, augslot5, augslot6, instnodrop, custom_data, ornamenticon, "
"ornamentidfile, ornament_hero_model "
"FROM inventory INNER JOIN character_data ch " "FROM inventory INNER JOIN character_data ch "
"ON ch.id = charid WHERE ch.name = '%s' AND ch.account_id = %i ORDER BY slotid", "ON ch.id = charid WHERE ch.name = '%s' AND ch.account_id = %i ORDER BY slotid",
name, account_id); name, account_id);
auto results = QueryDatabase(query); auto results = QueryDatabase(query);
if (!results.Success()){ if (!results.Success()) {
Log.Out(Logs::General, Logs::Error, "If you got an error related to the 'instnodrop' field, run the following SQL Queries:\nalter table inventory add instnodrop tinyint(1) unsigned default 0 not null;\n"); Log.Out(Logs::General, Logs::Error, "If you got an error related to the 'instnodrop' field, run the "
"following SQL Queries:\nalter table inventory add instnodrop "
"tinyint(1) unsigned default 0 not null;\n");
return false; return false;
} }
for (auto row = results.begin(); row != results.end(); ++row) { for (auto row = results.begin(); row != results.end(); ++row) {
int16 slot_id = atoi(row[0]); int16 slot_id = atoi(row[0]);
uint32 item_id = atoi(row[1]); uint32 item_id = atoi(row[1]);
@ -636,27 +649,27 @@ bool SharedDatabase::GetInventory(uint32 account_id, char* name, Inventory* inv)
uint32 ornament_idfile = (uint32)atoul(row[13]); uint32 ornament_idfile = (uint32)atoul(row[13]);
uint32 ornament_hero_model = (uint32)atoul(row[14]); uint32 ornament_hero_model = (uint32)atoul(row[14]);
const Item_Struct* item = GetItem(item_id); const Item_Struct *item = GetItem(item_id);
int16 put_slot_id = INVALID_INDEX; int16 put_slot_id = INVALID_INDEX;
if(!item) if (!item)
continue; continue;
ItemInst* inst = CreateBaseItem(item, charges); ItemInst *inst = CreateBaseItem(item, charges);
if (inst == nullptr) if (inst == nullptr)
continue; continue;
inst->SetAttuned(instnodrop); inst->SetAttuned(instnodrop);
if(row[11]) { if (row[11]) {
std::string data_str(row[11]); std::string data_str(row[11]);
std::string idAsString; std::string idAsString;
std::string value; std::string value;
bool use_id = true; bool use_id = true;
for(int i = 0; i < data_str.length(); ++i) { for (int i = 0; i < data_str.length(); ++i) {
if(data_str[i] == '^') { if (data_str[i] == '^') {
if(!use_id) { if (!use_id) {
inst->SetCustomData(idAsString, value); inst->SetCustomData(idAsString, value);
idAsString.clear(); idAsString.clear();
value.clear(); value.clear();
@ -667,11 +680,10 @@ bool SharedDatabase::GetInventory(uint32 account_id, char* name, Inventory* inv)
} }
char v = data_str[i]; char v = data_str[i];
if(use_id) if (use_id)
idAsString.push_back(v); idAsString.push_back(v);
else else
value.push_back(v); value.push_back(v);
} }
} }
@ -691,7 +703,7 @@ bool SharedDatabase::GetInventory(uint32 account_id, char* name, Inventory* inv)
} }
} }
if (slot_id>=8000 && slot_id <= 8999) if (slot_id >= 8000 && slot_id <= 8999)
put_slot_id = inv->PushCursor(*inst); put_slot_id = inv->PushCursor(*inst);
else else
put_slot_id = inv->PutItem(slot_id, *inst); put_slot_id = inv->PutItem(slot_id, *inst);
@ -700,16 +712,17 @@ bool SharedDatabase::GetInventory(uint32 account_id, char* name, Inventory* inv)
// Save ptr to item in inventory // Save ptr to item in inventory
if (put_slot_id == INVALID_INDEX) if (put_slot_id == INVALID_INDEX)
Log.Out(Logs::General, Logs::Error, "Warning: Invalid slot_id for item in inventory: name=%s, acctid=%i, item_id=%i, slot_id=%i", name, account_id, item_id, slot_id); Log.Out(Logs::General, Logs::Error, "Warning: Invalid slot_id for item in inventory: name=%s, "
"acctid=%i, item_id=%i, slot_id=%i",
name, account_id, item_id, slot_id);
} }
// Retrieve shared inventory // Retrieve shared inventory
return GetSharedBank(account_id, inv, false); return GetSharedBank(account_id, inv, false);
} }
void SharedDatabase::GetItemsCount(int32 &item_count, uint32 &max_id)
void SharedDatabase::GetItemsCount(int32 &item_count, uint32 &max_id) { {
item_count = -1; item_count = -1;
max_id = 0; max_id = 0;
@ -724,7 +737,7 @@ void SharedDatabase::GetItemsCount(int32 &item_count, uint32 &max_id) {
auto row = results.begin(); auto row = results.begin();
if(row[0]) if (row[0])
max_id = atoi(row[0]); max_id = atoi(row[0]);
if (row[1]) if (row[1])