void foo (int y) { int a = 0; if (y == 6) { a += bar (7); a += bar2 (6); } else { a += bar2 (6); a += bar (7); } baz (a); }
void graph2() { int inscor2=1; char ch; clrscr(); design(); gotoxy(20,23); printf("Pres Enter to go to MAIN MENU ..........."); textcolor(10); gotoxy(15,4); cprintf("************* GRAPH OF PROFIT *************"); textcolor(14); gotoxy(4,5); cprintf("PRODUCT NAME"); ptr=fopen("shop.dat","rb"); while((fread(&temp,sizeof(temp),1,ptr))==1) { printf("\n \xBA %s \t:",temp.desc); bar2(inscor2); } fclose(ptr); getche(); }
void VUMeter::drawBar(QPainter *painter) { painter->save(); QLinearGradient linGrad(50, 0, 50, 500); linGrad.setColorAt(0, colorHigh); linGrad.setColorAt(1, colorLow); linGrad.setSpread(QGradient::PadSpread); painter->setBrush(linGrad); //绘制柱状条 QRectF bar3(20, 50, 25, 450); painter->drawRect(bar3); QRectF bar4(55, 50, 25, 450); painter->drawRect(bar4); //绘制柱状背景 painter->setBrush(QColor(40, 40, 40)); double length = 450.0; double leftBar = abs(length * (minValue - leftValue) / (maxValue - minValue)); double rightBar = abs(length * (minValue - rightValue) / (maxValue - minValue)); QRectF bar1(20, 50, 25, 450 - leftBar); painter->drawRect(bar1); QRectF bar2(55, 50, 25, 450 - rightBar); painter->drawRect(bar2); painter->setPen(QPen(Qt::black, 2)); for (int i = 0; i <= 60; i++) { painter->drawLine(21, 500 - 450 * i / 60, 44, 500 - 450 * i / 60); painter->drawLine(56, 500 - 450 * i / 60, 79, 500 - 450 * i / 60); } painter->restore(); }
void foo (unsigned int a, unsigned int b) { if (a >= b) bar1 (); else if (a <= b) bar2 (); }
int main() { Foo foo; fprintf(stderr, "Foo::add(2,4) = %d\n" ,bar1(2,4, &foo, &Foo::add)); fprintf(stderr, "Foo::mult(3,5) = %d\n", bar2(3,5, &foo, &Foo::mult)); fprintf(stderr, "Foo::negate(6) = %d\n" , bar3(6, &Foo::negate)); return 0; }
int main (void) { struct S a = { 3, 4, 5 }, b = { 6, 7, 8 }, c = { 9, 10, 11 }; bar2 (b, a); bar3 (b, a, c); baz3 (c, a, b); return 0; }
int foo (void) { int len; if (bar1 (&len)) { char devpath [len]; if (bar2 (devpath) == len) return len; } return -1; }
int main() { want=vf_request; bar()->request(); want=vf_event; bar2()->event(); if (errs) { printf("FAIL\n"); return 1; } printf("PASS\n"); return 0; }
void testTortureExecute (void) { #if 0 struct S a = { 3, 4, 5 }, b = { 6, 7, 8 }, c = { 9, 10, 11 }; bar2 (b, a); bar3 (b, a, c); baz3 (c, a, b); return; #endif }
int main (void) { // make non-lazy reference to foo1 and bar1 pfoo1 = &foo1; pbar1 = &bar1; // make lazy reference to foo2 and bar2 foo2(); bar2(); // make non-lazy reference to foo_data2 and bar_data2 return *pfoo + *pbar + foo_data2 + bar_data2; }
void foo (void) { struct A e; if (bar2 (&e) < 0) abort (); { void baz (void) { bar (&e); } fnptr (baz); }
void tst_QStyleOption::copyconstructors() { QStyleOptionFrame frame; QStyleOptionFrameV2 frame2(frame); QCOMPARE(frame2.version, int(QStyleOptionFrameV2::Version)); frame2 = frame; QCOMPARE(frame2.version, int(QStyleOptionFrameV2::Version)); QStyleOptionProgressBar bar; QStyleOptionProgressBarV2 bar2(bar); QCOMPARE(bar2.version, int(QStyleOptionProgressBarV2::Version)); bar2 = bar; QCOMPARE(bar2.version, int(QStyleOptionProgressBarV2::Version)); }
JSBool facBar(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { diaElemBar bar1(25,"25"); diaElemBar bar2(65,"65"); diaElem *elems[]={&bar1,&bar2 }; if(diaFactoryRun("Test FileRead",2,elems)) { *rval = BOOLEAN_TO_JSVAL(1); }else *rval = BOOLEAN_TO_JSVAL(0); return JS_TRUE; }
int foo4 () { int result = 0; int f = -1; f = bar (); if (f < 0) { result = 1; goto bail; } bar (); bail: bar2 (f); return result; }
void foo (int a) { if (a < 100) return; if (200 < a) return; switch (a) { case 99: bar0 (); return; case 100: bar1 (); return; case 101: bar2 (); return; case 102: bar3 (); return; } }
void QProg::paintBar() { QPainter painter(this); painter.setWindow(0, 0, 470, 80); painter.setRenderHint(QPainter::Antialiasing); painter.setBrush(QColor(70, 70, 70)); //background color QRectF back(20, 10, 360, 60); painter.drawRoundRect(back, 3); // chech value if (actVal > maxVal) { return; } if (actVal < minVal) { return; } // waiting state if min = max if(minVal == maxVal) { painter.setBrush(colBar); QRectF bar(40, 10, 40, 60); QRectF bar1(130, 10, 40, 60); QRectF bar2(220, 10, 40, 60); QRectF bar3(310, 10, 40, 60); painter.drawRoundRect(bar, 3); painter.drawRoundRect(bar1, 3); painter.drawRoundRect(bar2, 3); painter.drawRoundRect(bar3, 3); return; } // check positive or negative scale if (maxVal >= 0 && minVal >= 0 || maxVal >= 0 && minVal <= 0) { lengthBar = 360-360 * (maxVal-actVal)/(maxVal-minVal); } if (maxVal <= 0 && minVal <= 0) { lengthBar = 360 * (minVal-actVal)/(minVal-maxVal); } // length and color bar painter.setBrush(colBar); QRectF bar(20, 10, lengthBar, 60); painter.drawRoundRect(bar, 3); emit valueChanged(actVal); }
//g++ ./test.cpp -std=c++11 -o ./test int main() { int x = 3; int& y = x; int const& z = bar(); //lvalues foo(x); foo(y); foo(z); //rvalues foo(4); foo(bar()); //this is also an rvalue foo(bar2()); }
int foo(void) { int a,b,g; int i,len; int stop; len = 10; stop = 0; for (i=0; i<len; i++) { a = bar1() ? 0 : 1; b = bar2() ? 0 : 1; g = bar3() ? 0 : 1; if (stop = ((a+b) % 2 != g)) break; } return stop; }
int foo1 (e_u8 a[4][N], int b1, int b2, e_u8 b[M+1][4][N]) { btype n; int r, m; switch (b2) { case 128: n = 4; break; case 192: n = 6; break; case 256: n = 8; break; default : return (-2); } switch (MAX(b1,b2)) { case 128: m = 10; break; case 192: m = 12; break; case 256: m = 14; break; default : return (-3); } bar1(a,b[m],n); bar2(a,x,n); return 0; }
void QVUMeter::paintBar() { QPainter painter(this); painter.setWindow(0, 0, 100, 540); painter.setRenderHint(QPainter::Antialiasing); QLinearGradient linGrad(50, 0, 50, 500); linGrad.setColorAt(0, colHigh); linGrad.setColorAt(1, colLow); linGrad.setSpread(QGradient::PadSpread); painter.setBrush(linGrad); // draw color bar QRectF bar3(20, 50, 25, 450); painter.drawRect(bar3); QRectF bar4(55, 50, 25, 450); painter.drawRect(bar4); // draw background bar painter.setBrush(QColor(40, 40, 40)); double length = 450.0; double leftBar = abs(length * (min-leftVal)/(max-min)); double rightBar = abs(length * (min-rightVal)/(max-min)); QRectF bar1(20, 50, 25, 450-leftBar); painter.drawRect(bar1); QRectF bar2(55, 50, 25, 450-rightBar); painter.drawRect(bar2); painter.setPen(QPen(Qt::black, 2)); for (int i = 0; i <=60; i++) { painter.drawLine(21, 500-450*i/60, 44, 500-450*i/60); painter.drawLine(56, 500-450*i/60, 79, 500-450*i/60); } }
void GameEventMgr::LoadFromDB() { { QueryResult *result = WorldDatabase.Query("SELECT MAX(entry) FROM game_event"); if( !result ) { sLog.outString(">> Table game_event is empty."); sLog.outString(); return; } Field *fields = result->Fetch(); uint32 max_event_id = fields[0].GetUInt16(); delete result; mGameEvent.resize(max_event_id+1); } QueryResult *result = WorldDatabase.Query("SELECT entry,UNIX_TIMESTAMP(start_time),UNIX_TIMESTAMP(end_time),occurence,length,holiday,description FROM game_event"); if( !result ) { mGameEvent.clear(); sLog.outString(">> Table game_event is empty!"); sLog.outString(); return; } uint32 count = 0; { barGoLink bar( (int)result->GetRowCount() ); do { ++count; Field *fields = result->Fetch(); bar.step(); uint16 event_id = fields[0].GetUInt16(); if(event_id==0) { sLog.outErrorDb("`game_event` game event id (%i) is reserved and can't be used.",event_id); continue; } GameEventData& pGameEvent = mGameEvent[event_id]; uint64 starttime = fields[1].GetUInt64(); pGameEvent.start = time_t(starttime); uint64 endtime = fields[2].GetUInt64(); pGameEvent.end = time_t(endtime); pGameEvent.occurence = fields[3].GetUInt32(); pGameEvent.length = fields[4].GetUInt32(); pGameEvent.holiday_id = fields[5].GetUInt32(); if(pGameEvent.length==0) // length>0 is validity check { sLog.outErrorDb("`game_event` game event id (%i) have length 0 and can't be used.",event_id); continue; } if(pGameEvent.holiday_id) { if(!sHolidaysStore.LookupEntry(pGameEvent.holiday_id)) { sLog.outErrorDb("`game_event` game event id (%i) have not existed holiday id %u.",event_id,pGameEvent.holiday_id); pGameEvent.holiday_id = 0; } } pGameEvent.description = fields[6].GetCppString(); } while( result->NextRow() ); delete result; sLog.outString(); sLog.outString( ">> Loaded %u game events", count ); } mGameEventCreatureGuids.resize(mGameEvent.size()*2-1); // 1 2 result = WorldDatabase.Query("SELECT creature.guid, game_event_creature.event " "FROM creature JOIN game_event_creature ON creature.guid = game_event_creature.guid"); count = 0; if( !result ) { barGoLink bar(1); bar.step(); sLog.outString(); sLog.outString(">> Loaded %u creatures in game events", count ); } else { barGoLink bar( (int)result->GetRowCount() ); do { Field *fields = result->Fetch(); bar.step(); uint32 guid = fields[0].GetUInt32(); int16 event_id = fields[1].GetInt16(); int32 internal_event_id = mGameEvent.size() + event_id - 1; if(internal_event_id < 0 || (size_t)internal_event_id >= mGameEventCreatureGuids.size()) { sLog.outErrorDb("`game_event_creature` game event id (%i) is out of range compared to max event id in `game_event`",event_id); continue; } ++count; GuidList& crelist = mGameEventCreatureGuids[internal_event_id]; crelist.push_back(guid); } while( result->NextRow() ); delete result; sLog.outString(); sLog.outString( ">> Loaded %u creatures in game events", count ); } mGameEventGameobjectGuids.resize(mGameEvent.size()*2-1); // 1 2 result = WorldDatabase.Query("SELECT gameobject.guid, game_event_gameobject.event " "FROM gameobject JOIN game_event_gameobject ON gameobject.guid=game_event_gameobject.guid"); count = 0; if( !result ) { barGoLink bar(1); bar.step(); sLog.outString(); sLog.outString(">> Loaded %u gameobjects in game events", count ); } else { barGoLink bar( (int)result->GetRowCount() ); do { Field *fields = result->Fetch(); bar.step(); uint32 guid = fields[0].GetUInt32(); int16 event_id = fields[1].GetInt16(); int32 internal_event_id = mGameEvent.size() + event_id - 1; if(internal_event_id < 0 || (size_t)internal_event_id >= mGameEventGameobjectGuids.size()) { sLog.outErrorDb("`game_event_gameobject` game event id (%i) is out of range compared to max event id in `game_event`",event_id); continue; } ++count; GuidList& golist = mGameEventGameobjectGuids[internal_event_id]; golist.push_back(guid); } while( result->NextRow() ); delete result; sLog.outString(); sLog.outString( ">> Loaded %u gameobjects in game events", count ); } mGameEventModelEquip.resize(mGameEvent.size()); // 0 1 2 result = WorldDatabase.Query("SELECT creature.guid, game_event_model_equip.event, game_event_model_equip.modelid," // 3 "game_event_model_equip.equipment_id " "FROM creature JOIN game_event_model_equip ON creature.guid=game_event_model_equip.guid"); count = 0; if( !result ) { barGoLink bar(1); bar.step(); sLog.outString(); sLog.outString(">> Loaded %u model/equipment changes in game events", count ); } else { barGoLink bar( (int)result->GetRowCount() ); do { Field *fields = result->Fetch(); bar.step(); uint32 guid = fields[0].GetUInt32(); uint16 event_id = fields[1].GetUInt16(); if(event_id >= mGameEventModelEquip.size()) { sLog.outErrorDb("`game_event_model_equip` game event id (%u) is out of range compared to max event id in `game_event`",event_id); continue; } ++count; ModelEquipList& equiplist = mGameEventModelEquip[event_id]; ModelEquip newModelEquipSet; newModelEquipSet.modelid = fields[2].GetUInt32(); newModelEquipSet.equipment_id = fields[3].GetUInt32(); newModelEquipSet.equipement_id_prev = 0; newModelEquipSet.modelid_prev = 0; if(newModelEquipSet.equipment_id > 0) { if(!sObjectMgr.GetEquipmentInfo(newModelEquipSet.equipment_id)) { sLog.outErrorDb("Table `game_event_model_equip` have creature (Guid: %u) with equipment_id %u not found in table `creature_equip_template`, set to no equipment.", guid, newModelEquipSet.equipment_id); continue; } } equiplist.push_back(std::pair<uint32, ModelEquip>(guid, newModelEquipSet)); } while( result->NextRow() ); delete result; sLog.outString(); sLog.outString( ">> Loaded %u model/equipment changes in game events", count ); } mGameEventQuests.resize(mGameEvent.size()); // 0 1 2 result = WorldDatabase.Query("SELECT id, quest, event FROM game_event_creature_quest"); count = 0; if( !result ) { barGoLink bar(1); bar.step(); sLog.outString(); sLog.outString(">> Loaded %u quests additions in game events", count ); } else { barGoLink bar( (int)result->GetRowCount() ); do { Field *fields = result->Fetch(); bar.step(); uint32 id = fields[0].GetUInt32(); uint32 quest = fields[1].GetUInt32(); uint16 event_id = fields[2].GetUInt16(); if(event_id >= mGameEventQuests.size()) { sLog.outErrorDb("`game_event_creature_quest` game event id (%u) is out of range compared to max event id in `game_event`",event_id); continue; } ++count; QuestRelList& questlist = mGameEventQuests[event_id]; questlist.push_back(QuestRelation(id, quest)); } while( result->NextRow() ); delete result; sLog.outString(); sLog.outString( ">> Loaded %u quests additions in game events", count ); } mGameEventPoolIds.resize(mGameEvent.size()*2-1); // 1 2 result = WorldDatabase.Query("SELECT pool_template.entry, game_event_pool.event " "FROM pool_template JOIN game_event_pool ON pool_template.entry = game_event_pool.pool_entry"); count = 0; if( !result ) { barGoLink bar2(1); bar2.step(); sLog.outString(); sLog.outString(">> Loaded %u pools in game events", count ); } else { barGoLink bar2( (int)result->GetRowCount() ); do { Field *fields = result->Fetch(); bar2.step(); uint32 entry = fields[0].GetUInt16(); int16 event_id = fields[1].GetInt16(); int32 internal_event_id = mGameEvent.size() + event_id - 1; if (internal_event_id < 0 || (size_t)internal_event_id >= mGameEventPoolIds.size()) { sLog.outErrorDb("`game_event_pool` game event id (%i) is out of range compared to max event id in `game_event`",event_id); continue; } if (!sPoolMgr.CheckPool(entry)) { sLog.outErrorDb("Pool Id (%u) has all creatures or gameobjects with explicit chance sum <>100 and no equal chance defined. The pool system cannot pick one to spawn.", entry); continue; } ++count; IdList& poollist = mGameEventPoolIds[internal_event_id]; poollist.push_back(entry); } while( result->NextRow() ); sLog.outString(); sLog.outString( ">> Loaded %u pools in game events", count ); delete result; } }
void PoolManager::LoadFromDB() { QueryResult* result = WorldDatabase.Query("SELECT MAX(entry) FROM pool_template"); if (!result) { sLog.outString(">> Table pool_template is empty."); sLog.outString(); return; } else { Field* fields = result->Fetch(); max_pool_id = fields[0].GetUInt16(); delete result; } mPoolTemplate.resize(max_pool_id + 1); result = WorldDatabase.Query("SELECT entry, max_limit, description FROM pool_template"); if (!result) { mPoolTemplate.clear(); sLog.outString(">> Table pool_template is empty:"); sLog.outString(); return; } uint32 count = 0; BarGoLink bar(result->GetRowCount()); do { ++count; Field* fields = result->Fetch(); bar.step(); uint16 pool_id = fields[0].GetUInt16(); PoolTemplateData& pPoolTemplate = mPoolTemplate[pool_id]; pPoolTemplate.MaxLimit = fields[1].GetUInt32(); pPoolTemplate.description = fields[2].GetCppString(); pPoolTemplate.AutoSpawn = true; // will update and later data loading } while (result->NextRow()); sLog.outString(); sLog.outString(">> Loaded %u objects pools", count); delete result; PoolMapChecker mapChecker(mPoolTemplate); // Creatures (guids and entries) mPoolCreatureGroups.resize(max_pool_id + 1); mCreatureSearchMap.clear(); // 1 2 3 result = WorldDatabase.Query("SELECT guid, pool_entry, chance FROM pool_creature"); count = 0; if (!result) { BarGoLink bar2(1); bar2.step(); sLog.outString(); sLog.outString(">> Loaded %u creatures in pools from `pool_creature`", count); } else { BarGoLink bar2(result->GetRowCount()); do { Field* fields = result->Fetch(); bar2.step(); uint32 guid = fields[0].GetUInt32(); uint16 pool_id = fields[1].GetUInt16(); float chance = fields[2].GetFloat(); CreatureData const* data = sObjectMgr.GetCreatureData(guid); if (!data) { sLog.outErrorDb("`pool_creature` has a non existing creature spawn (GUID: %u) defined for pool id (%u), skipped.", guid, pool_id); continue; } if (pool_id > max_pool_id) { sLog.outErrorDb("`pool_creature` pool id (%i) is out of range compared to max pool id in `pool_template`, skipped.", pool_id); continue; } if (chance < 0 || chance > 100) { sLog.outErrorDb("`pool_creature` has an invalid chance (%f) for creature guid (%u) in pool id (%i), skipped.", chance, guid, pool_id); continue; } if (!mapChecker.CheckAndRemember(data->mapid, pool_id, "pool_creature", "creature guid")) continue; PoolTemplateData* pPoolTemplate = &mPoolTemplate[pool_id]; ++count; PoolObject plObject = PoolObject(guid, chance); PoolGroup<Creature>& cregroup = mPoolCreatureGroups[pool_id]; cregroup.SetPoolId(pool_id); cregroup.AddEntry(plObject, pPoolTemplate->MaxLimit); SearchPair p(guid, pool_id); mCreatureSearchMap.insert(p); } while (result->NextRow()); sLog.outString(); sLog.outString(">> Loaded %u creatures in pools from `pool_creature`", count); delete result; } result = WorldDatabase.Query("SELECT guid, pool_entry, chance, pool_creature_template.id FROM pool_creature_template LEFT JOIN creature ON creature.id = pool_creature_template.id"); count = 0; if (!result) { BarGoLink bar2(1); bar2.step(); sLog.outString(); sLog.outString(">> Loaded %u creatures in pools from `pool_creature_template`", count); } else { BarGoLink bar2(result->GetRowCount()); do { Field* fields = result->Fetch(); bar2.step(); uint32 guid = fields[0].GetUInt32(); uint16 pool_id = fields[1].GetUInt16(); float chance = fields[2].GetFloat(); uint16 entry_id = fields[3].GetUInt32(); // for errors output only CreatureData const* data = sObjectMgr.GetCreatureData(guid); if (!data) { sLog.outErrorDb("`pool_creature_template` has a non existing creature spawn (GUID: %u Entry: %u) defined for pool id (%u), skipped.", guid, entry_id, pool_id); continue; } if (pool_id > max_pool_id) { sLog.outErrorDb("`pool_creature_template` pool id (%i) is out of range compared to max pool id in `pool_template`, skipped.", pool_id); continue; } if (chance < 0 || chance > 100) { sLog.outErrorDb("`pool_creature_template` has an invalid chance (%f) for creature (Guid %u Entry %u) in pool id (%i), skipped.", chance, guid, entry_id, pool_id); continue; } // `pool_creature` and `pool_creature_template` can't have guids duplicates (in second case because entries also unique) // So if guid already listed in pools then this duplicate from alt.table // Also note: for added guid not important what case we skip from 2 tables if (uint16 alt_pool_id = IsPartOfAPool<Creature>(guid)) { sLog.outErrorDb("`pool_creature` has guid %u for pool %u that already added to pool %u from `pool_creature_template` for creature entry %u, skipped.", guid, pool_id, alt_pool_id, entry_id); continue; } if (!mapChecker.CheckAndRemember(data->mapid, pool_id, "pool_creature_template", "creature guid")) continue; PoolTemplateData* pPoolTemplate = &mPoolTemplate[pool_id]; ++count; PoolObject plObject = PoolObject(guid, chance); PoolGroup<Creature>& cregroup = mPoolCreatureGroups[pool_id]; cregroup.SetPoolId(pool_id); cregroup.AddEntry(plObject, pPoolTemplate->MaxLimit); SearchPair p(guid, pool_id); mCreatureSearchMap.insert(p); } while (result->NextRow()); sLog.outString(); sLog.outString(">> Loaded %u creatures in pools from `pool_creature_template`", count); delete result; } // Gameobjects (guids and entries) mPoolGameobjectGroups.resize(max_pool_id + 1); mGameobjectSearchMap.clear(); // 1 2 3 result = WorldDatabase.Query("SELECT guid, pool_entry, chance FROM pool_gameobject"); count = 0; if (!result) { BarGoLink bar2(1); bar2.step(); sLog.outString(); sLog.outString(">> Loaded %u gameobject in pools from `pool_gameobject`", count); } else { BarGoLink bar2(result->GetRowCount()); do { Field* fields = result->Fetch(); bar2.step(); uint32 guid = fields[0].GetUInt32(); uint16 pool_id = fields[1].GetUInt16(); float chance = fields[2].GetFloat(); GameObjectData const* data = sObjectMgr.GetGOData(guid); if (!data) { sLog.outErrorDb("`pool_gameobject` has a non existing gameobject spawn (GUID: %u) defined for pool id (%u), skipped.", guid, pool_id); continue; } GameObjectInfo const* goinfo = ObjectMgr::GetGameObjectInfo(data->id); if (goinfo->type != GAMEOBJECT_TYPE_CHEST && goinfo->type != GAMEOBJECT_TYPE_GOOBER && goinfo->type != GAMEOBJECT_TYPE_FISHINGHOLE && goinfo->type != GAMEOBJECT_TYPE_TRAP) { sLog.outErrorDb("`pool_gameobject` has a not lootable gameobject spawn (GUID: %u, type: %u) defined for pool id (%u), skipped.", guid, goinfo->type, pool_id); continue; } if (pool_id > max_pool_id) { sLog.outErrorDb("`pool_gameobject` pool id (%i) is out of range compared to max pool id in `pool_template`, skipped.", pool_id); continue; } if (chance < 0 || chance > 100) { sLog.outErrorDb("`pool_gameobject` has an invalid chance (%f) for gameobject guid (%u) in pool id (%i), skipped.", chance, guid, pool_id); continue; } if (!mapChecker.CheckAndRemember(data->mapid, pool_id, "pool_gameobject", "gameobject guid")) continue; PoolTemplateData* pPoolTemplate = &mPoolTemplate[pool_id]; ++count; PoolObject plObject = PoolObject(guid, chance); PoolGroup<GameObject>& gogroup = mPoolGameobjectGroups[pool_id]; gogroup.SetPoolId(pool_id); gogroup.AddEntry(plObject, pPoolTemplate->MaxLimit); SearchPair p(guid, pool_id); mGameobjectSearchMap.insert(p); } while (result->NextRow()); sLog.outString(); sLog.outString(">> Loaded %u gameobject in pools from `pool_gameobject`", count); delete result; } // 1 2 3 result = WorldDatabase.Query("SELECT guid, pool_entry, chance, pool_gameobject_template.id FROM pool_gameobject_template LEFT JOIN gameobject ON gameobject.id = pool_gameobject_template.id"); count = 0; if (!result) { BarGoLink bar2(1); bar2.step(); sLog.outString(); sLog.outString(">> Loaded %u gameobject in pools from `pool_gameobject_template`", count); } else { BarGoLink bar2(result->GetRowCount()); do { Field* fields = result->Fetch(); bar2.step(); uint32 guid = fields[0].GetUInt32(); uint16 pool_id = fields[1].GetUInt16(); float chance = fields[2].GetFloat(); uint16 entry_id = fields[3].GetUInt32(); // for errors output only GameObjectData const* data = sObjectMgr.GetGOData(guid); if (!data) { sLog.outErrorDb("`pool_gameobject_template` has a non existing gameobject spawn (GUID: %u Entry %u) defined for pool id (%u), skipped.", guid, entry_id, pool_id); continue; } GameObjectInfo const* goinfo = ObjectMgr::GetGameObjectInfo(data->id); if (goinfo->type != GAMEOBJECT_TYPE_CHEST && goinfo->type != GAMEOBJECT_TYPE_GOOBER && goinfo->type != GAMEOBJECT_TYPE_FISHINGHOLE && goinfo->type != GAMEOBJECT_TYPE_TRAP) { sLog.outErrorDb("`pool_gameobject_template` has a not lootable gameobject spawn (GUID: %u Entry %u Type: %u) defined for pool id (%u), skipped.", guid, entry_id, goinfo->type, pool_id); continue; } if (pool_id > max_pool_id) { sLog.outErrorDb("`pool_gameobject_template` pool id (%i) is out of range compared to max pool id in `pool_template`, skipped.", pool_id); continue; } if (chance < 0 || chance > 100) { sLog.outErrorDb("`pool_gameobject_template` has an invalid chance (%f) for gameobject (Guid %u Entry %u) in pool id (%i), skipped.", chance, guid, entry_id, pool_id); continue; } // `pool_gameobject` and `pool_gameobject_template` can't have guids duplicates (in second case because entries also unique) // So if guid already listed in pools then this duplicate from alt.table // Also note: for added guid not important what case we skip from 2 tables if (uint16 alt_pool_id = IsPartOfAPool<GameObject>(guid)) { sLog.outErrorDb("`pool_gameobject` has guid %u for pool %u that already added to pool %u from `pool_gameobject_template` for gameobject entry %u, skipped.", guid, pool_id, alt_pool_id, entry_id); continue; } if (!mapChecker.CheckAndRemember(data->mapid, pool_id, "pool_gameobject_template", "gameobject guid")) continue; PoolTemplateData* pPoolTemplate = &mPoolTemplate[pool_id]; ++count; PoolObject plObject = PoolObject(guid, chance); PoolGroup<GameObject>& gogroup = mPoolGameobjectGroups[pool_id]; gogroup.SetPoolId(pool_id); gogroup.AddEntry(plObject, pPoolTemplate->MaxLimit); SearchPair p(guid, pool_id); mGameobjectSearchMap.insert(p); } while (result->NextRow()); sLog.outString(); sLog.outString(">> Loaded %u gameobject in pools from `pool_gameobject_template`", count); delete result; } // Pool of pools mPoolPoolGroups.resize(max_pool_id + 1); // 1 2 3 result = WorldDatabase.Query("SELECT pool_id, mother_pool, chance FROM pool_pool"); count = 0; if (!result) { BarGoLink bar2(1); bar2.step(); sLog.outString(); sLog.outString(">> Loaded %u pools in pools", count); } else { BarGoLink bar2(result->GetRowCount()); do { Field* fields = result->Fetch(); bar2.step(); uint16 child_pool_id = fields[0].GetUInt16(); uint16 mother_pool_id = fields[1].GetUInt16(); float chance = fields[2].GetFloat(); if (mother_pool_id > max_pool_id) { sLog.outErrorDb("`pool_pool` mother_pool id (%i) is out of range compared to max pool id in `pool_template`, skipped.", mother_pool_id); continue; } if (child_pool_id > max_pool_id) { sLog.outErrorDb("`pool_pool` included pool_id (%i) is out of range compared to max pool id in `pool_template`, skipped.", child_pool_id); continue; } if (mother_pool_id == child_pool_id) { sLog.outErrorDb("`pool_pool` pool_id (%i) includes itself, dead-lock detected, skipped.", child_pool_id); continue; } if (chance < 0 || chance > 100) { sLog.outErrorDb("`pool_pool` has an invalid chance (%f) for pool id (%u) in mother pool id (%i), skipped.", chance, child_pool_id, mother_pool_id); continue; } PoolTemplateData* pPoolTemplateMother = &mPoolTemplate[mother_pool_id]; ++count; PoolObject plObject = PoolObject(child_pool_id, chance); PoolGroup<Pool>& plgroup = mPoolPoolGroups[mother_pool_id]; plgroup.SetPoolId(mother_pool_id); plgroup.AddEntry(plObject, pPoolTemplateMother->MaxLimit); SearchPair p(child_pool_id, mother_pool_id); mPoolSearchMap.insert(p); // update top independent pool flag mPoolTemplate[child_pool_id].AutoSpawn = false; } while (result->NextRow()); // Now check for circular reference for (uint16 i = 0; i < max_pool_id; ++i) { std::set<uint16> checkedPools; for (SearchMap::iterator poolItr = mPoolSearchMap.find(i); poolItr != mPoolSearchMap.end(); poolItr = mPoolSearchMap.find(poolItr->second)) { // if child pool not have map data then it empty or have not checked child then will checked and all line later if (MapEntry const* childMapEntry = mPoolTemplate[poolItr->first].mapEntry) { if (!mapChecker.CheckAndRemember(childMapEntry->MapID, poolItr->second, "pool_pool", "pool with creature/gameobject")) { mPoolPoolGroups[poolItr->second].RemoveOneRelation(poolItr->first); mPoolSearchMap.erase(poolItr); --count; break; } } checkedPools.insert(poolItr->first); if (checkedPools.find(poolItr->second) != checkedPools.end()) { std::ostringstream ss; ss << "The pool(s) "; for (std::set<uint16>::const_iterator itr = checkedPools.begin(); itr != checkedPools.end(); ++itr) ss << *itr << " "; ss << "create(s) a circular reference, which can cause the server to freeze.\nRemoving the last link between mother pool " << poolItr->first << " and child pool " << poolItr->second; sLog.outErrorDb("%s", ss.str().c_str()); mPoolPoolGroups[poolItr->second].RemoveOneRelation(poolItr->first); mPoolSearchMap.erase(poolItr); --count; break; } } } sLog.outString(); sLog.outString(">> Loaded %u pools in mother pools", count); delete result; } // check chances integrity for (uint16 pool_entry = 0; pool_entry < mPoolTemplate.size(); ++pool_entry) { if (mPoolTemplate[pool_entry].AutoSpawn) { if (!CheckPool(pool_entry)) { sLog.outErrorDb("Pool Id (%u) has all creatures or gameobjects with explicit chance sum <>100 and no equal chance defined. The pool system cannot pick one to spawn.", pool_entry); mPoolTemplate[pool_entry].AutoSpawn = false; } } } }
void PoolManager::LoadFromDB() { QueryResult* result = WorldDatabase.Query("SELECT MAX(entry) FROM pool_template"); if (!result) { sLog.outString(">> Table pool_template is empty."); sLog.outString(); return; } else { Field* fields = result->Fetch(); max_pool_id = fields[0].GetUInt16(); delete result; } mPoolTemplate.resize(max_pool_id + 1); result = WorldDatabase.Query("SELECT entry, max_limit, description FROM pool_template"); if (!result) { mPoolTemplate.clear(); sLog.outString(">> Table pool_template is empty:"); sLog.outString(); return; } uint32 count = 0; BarGoLink bar(result->GetRowCount()); do { ++count; Field* fields = result->Fetch(); bar.step(); uint16 pool_id = fields[0].GetUInt16(); PoolTemplateData& pPoolTemplate = mPoolTemplate[pool_id]; pPoolTemplate.MaxLimit = fields[1].GetUInt32(); pPoolTemplate.description = fields[2].GetCppString(); pPoolTemplate.AutoSpawn = true; // will update and later data loading } while (result->NextRow()); sLog.outString(); sLog.outString(">> Loaded %u objects pools", count); delete result; PoolMapChecker mapChecker(mPoolTemplate); // Creatures (guids and entries) mPoolCreatureGroups.resize(max_pool_id + 1); mCreatureSearchMap.clear(); // 1 2 3 result = WorldDatabase.Query("SELECT guid, pool_entry, chance FROM pool_creature"); count = 0; if (!result) { BarGoLink bar2(1); bar2.step(); sLog.outString(); sLog.outString(">> Loaded %u creatures in pools from `pool_creature`", count); } else { BarGoLink bar2(result->GetRowCount()); do { Field* fields = result->Fetch(); bar2.step(); uint32 guid = fields[0].GetUInt32(); uint16 pool_id = fields[1].GetUInt16(); float chance = fields[2].GetFloat(); CreatureData const* data = sObjectMgr.GetCreatureData(guid); if (!data) { sLog.outErrorDb("`pool_creature` has a non existing creature spawn (GUID: %u) defined for pool id (%u), skipped.", guid, pool_id); continue; } if (pool_id > max_pool_id) { sLog.outErrorDb("`pool_creature` pool id (%i) is out of range compared to max pool id in `pool_template`, skipped.", pool_id); continue; } if (chance < 0 || chance > 100) { sLog.outErrorDb("`pool_creature` has an invalid chance (%f) for creature guid (%u) in pool id (%i), skipped.", chance, guid, pool_id); continue; } if (!mapChecker.CheckAndRemember(data->mapid, pool_id, "pool_creature", "creature guid", guid)) { continue; } PoolTemplateData* pPoolTemplate = &mPoolTemplate[pool_id]; ++count; PoolObject plObject = PoolObject(guid, chance); PoolGroup<Creature>& cregroup = mPoolCreatureGroups[pool_id]; cregroup.SetPoolId(pool_id); cregroup.AddEntry(plObject, pPoolTemplate->MaxLimit); SearchPair p(guid, pool_id); mCreatureSearchMap.insert(p); } while (result->NextRow()); sLog.outString(); sLog.outString(">> Loaded %u creatures in pools from `pool_creature`", count); delete result; } result = WorldDatabase.Query("SELECT guid, pool_entry, chance, pool_creature_template.id FROM pool_creature_template LEFT JOIN creature ON creature.id = pool_creature_template.id"); count = 0; if (!result) { BarGoLink bar2(1); bar2.step(); sLog.outString(); sLog.outString(">> Loaded %u creatures in pools from `pool_creature_template`", count); } else { BarGoLink bar2(result->GetRowCount()); do { Field* fields = result->Fetch(); bar2.step(); uint32 guid = fields[0].GetUInt32(); uint16 pool_id = fields[1].GetUInt16(); float chance = fields[2].GetFloat(); uint16 entry_id = fields[3].GetUInt32(); // for errors output only CreatureData const* data = sObjectMgr.GetCreatureData(guid); if (!data) { sLog.outErrorDb("`pool_creature_template` has a non existing creature spawn (GUID: %u Entry: %u) defined for pool id (%u), skipped.", guid, entry_id, pool_id); continue; } if (pool_id > max_pool_id) { sLog.outErrorDb("`pool_creature_template` pool id (%i) is out of range compared to max pool id in `pool_template`, skipped.", pool_id); continue; } if (chance < 0 || chance > 100) { sLog.outErrorDb("`pool_creature_template` has an invalid chance (%f) for creature (Guid %u Entry %u) in pool id (%i), skipped.", chance, guid, entry_id, pool_id); continue; } // `pool_creature` and `pool_creature_template` can't have guids duplicates (in second case because entries also unique) // So if guid already listed in pools then this duplicate from alt.table // Also note: for added guid not important what case we skip from 2 tables if (uint16 alt_pool_id = IsPartOfAPool<Creature>(guid)) { sLog.outErrorDb("`pool_creature` has guid %u for pool %u that already added to pool %u from `pool_creature_template` for creature entry %u, skipped.", guid, pool_id, alt_pool_id, entry_id); continue; } if (!mapChecker.CheckAndRemember(data->mapid, pool_id, "pool_creature_template", "creature guid", guid)) { continue; } PoolTemplateData* pPoolTemplate = &mPoolTemplate[pool_id]; ++count; PoolObject plObject = PoolObject(guid, chance); PoolGroup<Creature>& cregroup = mPoolCreatureGroups[pool_id]; cregroup.SetPoolId(pool_id); cregroup.AddEntry(plObject, pPoolTemplate->MaxLimit); SearchPair p(guid, pool_id); mCreatureSearchMap.insert(p); } while (result->NextRow()); sLog.outString(); sLog.outString(">> Loaded %u creatures in pools from `pool_creature_template`", count); delete result; } // Gameobjects (guids and entries) mPoolGameobjectGroups.resize(max_pool_id + 1); mGameobjectSearchMap.clear(); // 1 2 3 result = WorldDatabase.Query("SELECT guid, pool_entry, chance FROM pool_gameobject"); count = 0; if (!result) { BarGoLink bar2(1); bar2.step(); sLog.outString(); sLog.outString(">> Loaded %u gameobject in pools from `pool_gameobject`", count); } else { BarGoLink bar2(result->GetRowCount()); do { Field* fields = result->Fetch(); bar2.step(); uint32 guid = fields[0].GetUInt32(); uint16 pool_id = fields[1].GetUInt16(); float chance = fields[2].GetFloat(); GameObjectData const* data = sObjectMgr.GetGOData(guid); if (!data) { sLog.outErrorDb("`pool_gameobject` has a non existing gameobject spawn (GUID: %u) defined for pool id (%u), skipped.", guid, pool_id); continue; } if (pool_id > max_pool_id) { sLog.outErrorDb("`pool_gameobject` pool id (%i) is out of range compared to max pool id in `pool_template`, skipped.", pool_id); continue; } if (chance < 0 || chance > 100) { sLog.outErrorDb("`pool_gameobject` has an invalid chance (%f) for gameobject guid (%u) in pool id (%i), skipped.", chance, guid, pool_id); continue; } if (!mapChecker.CheckAndRemember(data->mapid, pool_id, "pool_gameobject", "gameobject guid", guid)) { continue; } PoolTemplateData* pPoolTemplate = &mPoolTemplate[pool_id]; ++count; PoolObject plObject = PoolObject(guid, chance); PoolGroup<GameObject>& gogroup = mPoolGameobjectGroups[pool_id]; gogroup.SetPoolId(pool_id); gogroup.AddEntry(plObject, pPoolTemplate->MaxLimit); SearchPair p(guid, pool_id); mGameobjectSearchMap.insert(p); } while (result->NextRow()); sLog.outString(); sLog.outString(">> Loaded %u gameobject in pools from `pool_gameobject`", count); delete result; } // 1 2 3 result = WorldDatabase.Query("SELECT guid, pool_entry, chance, pool_gameobject_template.id FROM pool_gameobject_template LEFT JOIN gameobject ON gameobject.id = pool_gameobject_template.id"); count = 0; if (!result) { BarGoLink bar2(1); bar2.step(); sLog.outString(); sLog.outString(">> Loaded %u gameobject in pools from `pool_gameobject_template`", count); } else { BarGoLink bar2(result->GetRowCount()); do { Field* fields = result->Fetch(); bar2.step(); uint32 guid = fields[0].GetUInt32(); uint16 pool_id = fields[1].GetUInt16(); float chance = fields[2].GetFloat(); uint16 entry_id = fields[3].GetUInt32(); // for errors output only GameObjectData const* data = sObjectMgr.GetGOData(guid); if (!data) { sLog.outErrorDb("`pool_gameobject_template` has a non existing gameobject spawn (GUID: %u Entry %u) defined for pool id (%u), skipped.", guid, entry_id, pool_id); continue; } if (pool_id > max_pool_id) { sLog.outErrorDb("`pool_gameobject_template` pool id (%i) is out of range compared to max pool id in `pool_template`, skipped.", pool_id); continue; } if (chance < 0 || chance > 100) { sLog.outErrorDb("`pool_gameobject_template` has an invalid chance (%f) for gameobject (Guid %u Entry %u) in pool id (%i), skipped.", chance, guid, entry_id, pool_id); continue; } // `pool_gameobject` and `pool_gameobject_template` can't have guids duplicates (in second case because entries also unique) // So if guid already listed in pools then this duplicate from alt.table // Also note: for added guid not important what case we skip from 2 tables if (uint16 alt_pool_id = IsPartOfAPool<GameObject>(guid)) { sLog.outErrorDb("`pool_gameobject` has guid %u for pool %u that already added to pool %u from `pool_gameobject_template` for gameobject entry %u, skipped.", guid, pool_id, alt_pool_id, entry_id); continue; } if (!mapChecker.CheckAndRemember(data->mapid, pool_id, "pool_gameobject_template", "gameobject guid", guid)) { continue; } PoolTemplateData* pPoolTemplate = &mPoolTemplate[pool_id]; ++count; PoolObject plObject = PoolObject(guid, chance); PoolGroup<GameObject>& gogroup = mPoolGameobjectGroups[pool_id]; gogroup.SetPoolId(pool_id); gogroup.AddEntry(plObject, pPoolTemplate->MaxLimit); SearchPair p(guid, pool_id); mGameobjectSearchMap.insert(p); } while (result->NextRow()); sLog.outString(); sLog.outString(">> Loaded %u gameobject in pools from `pool_gameobject_template`", count); delete result; } // Pool of pools mPoolPoolGroups.resize(max_pool_id + 1); // 1 2 3 result = WorldDatabase.Query("SELECT pool_id, mother_pool, chance FROM pool_pool"); count = 0; if (!result) { BarGoLink bar2(1); bar2.step(); sLog.outString(); sLog.outString(">> Loaded %u pools in pools", count); } else { BarGoLink bar2(result->GetRowCount()); do { Field* fields = result->Fetch(); bar2.step(); uint16 child_pool_id = fields[0].GetUInt16(); uint16 mother_pool_id = fields[1].GetUInt16(); float chance = fields[2].GetFloat(); if (mother_pool_id > max_pool_id) { sLog.outErrorDb("`pool_pool` mother_pool id (%i) is out of range compared to max pool id in `pool_template`, skipped.", mother_pool_id); continue; } if (child_pool_id > max_pool_id) { sLog.outErrorDb("`pool_pool` included pool_id (%i) is out of range compared to max pool id in `pool_template`, skipped.", child_pool_id); continue; } if (mother_pool_id == child_pool_id) { sLog.outErrorDb("`pool_pool` pool_id (%i) includes itself, dead-lock detected, skipped.", child_pool_id); continue; } if (chance < 0 || chance > 100) { sLog.outErrorDb("`pool_pool` has an invalid chance (%f) for pool id (%u) in mother pool id (%i), skipped.", chance, child_pool_id, mother_pool_id); continue; } PoolTemplateData* pPoolTemplateMother = &mPoolTemplate[mother_pool_id]; ++count; PoolObject plObject = PoolObject(child_pool_id, chance); PoolGroup<Pool>& plgroup = mPoolPoolGroups[mother_pool_id]; plgroup.SetPoolId(mother_pool_id); plgroup.AddEntry(plObject, pPoolTemplateMother->MaxLimit); SearchPair p(child_pool_id, mother_pool_id); mPoolSearchMap.insert(p); // update top independent pool flag mPoolTemplate[child_pool_id].AutoSpawn = false; } while (result->NextRow()); // Now check for circular reference for (uint16 i = 0; i < max_pool_id; ++i) { std::set<uint16> checkedPools; for (SearchMap::iterator poolItr = mPoolSearchMap.find(i); poolItr != mPoolSearchMap.end(); poolItr = mPoolSearchMap.find(poolItr->second)) { // if child pool not have map data then it empty or have not checked child then will checked and all line later if (MapEntry const* childMapEntry = mPoolTemplate[poolItr->first].mapEntry) { if (!mapChecker.CheckAndRemember(childMapEntry->MapID, poolItr->second, "pool_pool", "pool with creature/gameobject", poolItr->first)) { mPoolPoolGroups[poolItr->second].RemoveOneRelation(poolItr->first); mPoolSearchMap.erase(poolItr); --count; break; } } checkedPools.insert(poolItr->first); if (checkedPools.find(poolItr->second) != checkedPools.end()) { std::ostringstream ss; ss << "The pool(s) "; for (std::set<uint16>::const_iterator itr = checkedPools.begin(); itr != checkedPools.end(); ++itr) { ss << *itr << " "; } ss << "create(s) a circular reference, which can cause the server to freeze.\nRemoving the last link between mother pool " << poolItr->first << " and child pool " << poolItr->second; sLog.outErrorDb("%s", ss.str().c_str()); mPoolPoolGroups[poolItr->second].RemoveOneRelation(poolItr->first); mPoolSearchMap.erase(poolItr); --count; break; } } } sLog.outString(); sLog.outString(">> Loaded %u pools in mother pools", count); delete result; } // check chances integrity for (uint16 pool_entry = 0; pool_entry < mPoolTemplate.size(); ++pool_entry) { if (mPoolTemplate[pool_entry].AutoSpawn) { if (!CheckPool(pool_entry)) { sLog.outErrorDb("Pool Id (%u) has all creatures or gameobjects with explicit chance sum <>100 and no equal chance defined. The pool system can not pick one to spawn.", pool_entry); mPoolTemplate[pool_entry].AutoSpawn = false; } } } /*if (sWorld.getConfig(CONFIG_BOOL_AUTOPOOLING_MINING_ENABLE)) { // autocreate mining pools mPoolTemplate.resize(max_pool_id + 3486 + 533); //values are hardcoded for max zoneID and max MapID it would be better to read max IDs from the .dbc files mPoolCreatureGroups.resize(max_pool_id + 3486 + 533); mPoolGameobjectGroups.resize(max_pool_id + 3486 + 533); mPoolPoolGroups.resize(max_pool_id + 3486 + 533); uint32 max_autopool_entry = (max_pool_id + 3486 + 533); for (uint16 pool_entry = max_pool_id + 1; pool_entry < max_autopool_entry; ++pool_entry) { PoolTemplateData& pPoolTemplate = mPoolTemplate[pool_entry]; pPoolTemplate.MaxLimit = 0; std::ostringstream sZone; sZone << "autopool zone " << pool_entry; pPoolTemplate.description = sZone.str(); pPoolTemplate.AutoSpawn = true; // will update and later data loading } count = 0; // 0 1 2 3 4 5 result = WorldDatabase.Query("SELECT gameobject.guid, gameobject.id, map, position_x, position_y, position_z," // 6 7 "pool_gameobject.pool_entry, pool_gameobject_template.pool_entry " "FROM gameobject " "LEFT OUTER JOIN pool_gameobject ON gameobject.guid = pool_gameobject.guid " "LEFT OUTER JOIN pool_gameobject_template ON gameobject.id = pool_gameobject_template.id"); if (!result) { BarGoLink bar3(1); bar3.step(); sLog.outString(); sLog.outErrorDb(">> Loaded 0 gameobjects. DB table `gameobject` is empty."); return; } BarGoLink bar3(result->GetRowCount()); do { Field* fields = result->Fetch(); bar3.step(); uint32 guid = fields[ 0].GetUInt32(); uint32 entry = fields[ 1].GetUInt32(); uint32 map = fields[ 2].GetUInt32(); float posX = fields[ 3].GetFloat(); float posY = fields[ 4].GetFloat(); float posZ = fields[ 5].GetFloat(); int16 GuidPoolId = fields[6].GetInt16(); int16 EntryPoolId = fields[7].GetInt16(); if (GuidPoolId != 0 || EntryPoolId != 0) // if not this is in the pool system already { continue; } GameObjectInfo const* goinfo = ObjectMgr::GetGameObjectInfo(entry); if (goinfo->type != GAMEOBJECT_TYPE_CHEST) { continue; } if (goinfo->chest.minSuccessOpens != 0 && goinfo->chest.maxSuccessOpens > goinfo->chest.minSuccessOpens) //in this case it is a mineral vein { uint32 zone_id; uint16 pool_id; if (map == 0 || map == 1) { zone_id = sTerrainMgr.LoadTerrain(map)->GetZoneId(posX, posY, posZ); pool_id = zone_id + max_pool_id; } else { zone_id = map; pool_id = zone_id + max_pool_id + 3486; //3486 zero value for maxzoneID } PoolTemplateData* pPoolTemplate = &mPoolTemplate[pool_id]; PoolObject plObject = PoolObject(guid, 0); PoolGroup<GameObject>& gogroup = mPoolGameobjectGroups[pool_id]; gogroup.SetPoolId(pool_id); gogroup.AddEntry(plObject, 0); SearchPair p(guid, pool_id); mGameobjectSearchMap.insert(p); if (!mapChecker.CheckAndRemember(map, pool_id, "pool_gameobject", "gameobject guid", guid)) { continue; } ++count; //sLog.outErrorDb("UPDATE gameobject SET zone_id=%u, area_id=%u WHERE guid=%u;", zoneId, areaId, guid); } } while (result->NextRow()); for (uint16 pool_entry = max_pool_id + 1; pool_entry < max_autopool_entry; ++pool_entry) { uint32 poolsize; PoolTemplateData& pPoolTemplate = mPoolTemplate[pool_entry]; PoolGroup<GameObject>& gogroup = mPoolGameobjectGroups[pool_entry]; poolsize = gogroup.size(); pPoolTemplate.MaxLimit = (poolsize * CONFIG_UINT32_RATE_MINING_AUTOPOOLING) / 100; } delete result; sLog.outString(">> Loaded %u mining nodes", count); }*/ }
void PoolManager::LoadFromDB() { QueryResult *result = WorldDatabase.Query("SELECT MAX(entry) FROM pool_template"); if (!result) { sLog.outString(">> Table pool_template is empty."); sLog.outString(); return; } else { Field *fields = result->Fetch(); max_pool_id = fields[0].GetUInt16(); delete result; } mPoolTemplate.resize(max_pool_id + 1); result = WorldDatabase.Query("SELECT entry,max_limit FROM pool_template"); if (!result) { mPoolTemplate.clear(); sLog.outString(">> Table pool_template is empty:"); sLog.outString(); return; } uint32 count = 0; barGoLink bar((int)result->GetRowCount()); do { ++count; Field *fields = result->Fetch(); bar.step(); uint16 pool_id = fields[0].GetUInt16(); PoolTemplateData& pPoolTemplate = mPoolTemplate[pool_id]; pPoolTemplate.MaxLimit = fields[1].GetUInt32(); pPoolTemplate.AutoSpawn = true; // will update and later data loading } while (result->NextRow()); sLog.outString(); sLog.outString( ">> Loaded %u objects pools", count ); delete result; // Creatures mPoolCreatureGroups.resize(max_pool_id + 1); mCreatureSearchMap.clear(); // 1 2 3 result = WorldDatabase.Query("SELECT guid, pool_entry, chance FROM pool_creature"); count = 0; if (!result) { barGoLink bar2(1); bar2.step(); sLog.outString(); sLog.outString(">> Loaded %u creatures in pools", count ); } else { barGoLink bar2((int)result->GetRowCount()); do { Field *fields = result->Fetch(); bar2.step(); uint32 guid = fields[0].GetUInt32(); uint16 pool_id = fields[1].GetUInt16(); float chance = fields[2].GetFloat(); CreatureData const* data = sObjectMgr.GetCreatureData(guid); if (!data) { sLog.outErrorDb("`pool_creature` has a non existing creature spawn (GUID: %u) defined for pool id (%u), skipped.", guid, pool_id ); continue; } if (pool_id > max_pool_id) { sLog.outErrorDb("`pool_creature` pool id (%i) is out of range compared to max pool id in `pool_template`, skipped.",pool_id); continue; } if (chance < 0 || chance > 100) { sLog.outErrorDb("`pool_creature` has an invalid chance (%f) for creature guid (%u) in pool id (%i), skipped.", chance, guid, pool_id); continue; } PoolTemplateData *pPoolTemplate = &mPoolTemplate[pool_id]; ++count; PoolObject plObject = PoolObject(guid, chance); PoolGroup<Creature>& cregroup = mPoolCreatureGroups[pool_id]; cregroup.SetPoolId(pool_id); cregroup.AddEntry(plObject, pPoolTemplate->MaxLimit); SearchPair p(guid, pool_id); mCreatureSearchMap.insert(p); } while (result->NextRow()); sLog.outString(); sLog.outString( ">> Loaded %u creatures in pools", count ); delete result; } // Gameobjects mPoolGameobjectGroups.resize(max_pool_id + 1); mGameobjectSearchMap.clear(); // 1 2 3 result = WorldDatabase.Query("SELECT guid, pool_entry, chance FROM pool_gameobject"); count = 0; if (!result) { barGoLink bar2(1); bar2.step(); sLog.outString(); sLog.outString(">> Loaded %u gameobject in pools", count ); } else { barGoLink bar2((int)result->GetRowCount()); do { Field *fields = result->Fetch(); bar2.step(); uint32 guid = fields[0].GetUInt32(); uint16 pool_id = fields[1].GetUInt16(); float chance = fields[2].GetFloat(); GameObjectData const* data = sObjectMgr.GetGOData(guid); if (!data) { sLog.outErrorDb("`pool_gameobject` has a non existing gameobject spawn (GUID: %u) defined for pool id (%u), skipped.", guid, pool_id ); continue; } GameObjectInfo const* goinfo = ObjectMgr::GetGameObjectInfo(data->id); if (goinfo->type != GAMEOBJECT_TYPE_CHEST && goinfo->type != GAMEOBJECT_TYPE_GOOBER && goinfo->type != GAMEOBJECT_TYPE_FISHINGHOLE) { sLog.outErrorDb("`pool_gameobject` has a not lootable gameobject spawn (GUID: %u, type: %u) defined for pool id (%u), skipped.", guid, goinfo->type, pool_id ); continue; } if (pool_id > max_pool_id) { sLog.outErrorDb("`pool_gameobject` pool id (%i) is out of range compared to max pool id in `pool_template`, skipped.",pool_id); continue; } if (chance < 0 || chance > 100) { sLog.outErrorDb("`pool_gameobject` has an invalid chance (%f) for gameobject guid (%u) in pool id (%i), skipped.", chance, guid, pool_id); continue; } PoolTemplateData *pPoolTemplate = &mPoolTemplate[pool_id]; ++count; PoolObject plObject = PoolObject(guid, chance); PoolGroup<GameObject>& gogroup = mPoolGameobjectGroups[pool_id]; gogroup.SetPoolId(pool_id); gogroup.AddEntry(plObject, pPoolTemplate->MaxLimit); SearchPair p(guid, pool_id); mGameobjectSearchMap.insert(p); } while( result->NextRow() ); sLog.outString(); sLog.outString( ">> Loaded %u gameobject in pools", count ); delete result; } // Pool of pools mPoolPoolGroups.resize(max_pool_id + 1); // 1 2 3 result = WorldDatabase.Query("SELECT pool_id, mother_pool, chance FROM pool_pool"); count = 0; if( !result ) { barGoLink bar2(1); bar2.step(); sLog.outString(); sLog.outString(">> Loaded %u pools in pools", count ); } else { barGoLink bar2( (int)result->GetRowCount() ); do { Field *fields = result->Fetch(); bar2.step(); uint16 child_pool_id = fields[0].GetUInt16(); uint16 mother_pool_id = fields[1].GetUInt16(); float chance = fields[2].GetFloat(); if (mother_pool_id > max_pool_id) { sLog.outErrorDb("`pool_pool` mother_pool id (%i) is out of range compared to max pool id in `pool_template`, skipped.",mother_pool_id); continue; } if (child_pool_id > max_pool_id) { sLog.outErrorDb("`pool_pool` included pool_id (%i) is out of range compared to max pool id in `pool_template`, skipped.",child_pool_id); continue; } if (mother_pool_id == child_pool_id) { sLog.outErrorDb("`pool_pool` pool_id (%i) includes itself, dead-lock detected, skipped.",child_pool_id); continue; } if (chance < 0 || chance > 100) { sLog.outErrorDb("`pool_pool` has an invalid chance (%f) for pool id (%u) in mother pool id (%i), skipped.", chance, child_pool_id, mother_pool_id); continue; } PoolTemplateData *pPoolTemplateMother = &mPoolTemplate[mother_pool_id]; ++count; PoolObject plObject = PoolObject(child_pool_id, chance); PoolGroup<Pool>& plgroup = mPoolPoolGroups[mother_pool_id]; plgroup.SetPoolId(mother_pool_id); plgroup.AddEntry(plObject, pPoolTemplateMother->MaxLimit); SearchPair p(child_pool_id, mother_pool_id); mPoolSearchMap.insert(p); // update top independent pool flag mPoolTemplate[child_pool_id].AutoSpawn = false; } while( result->NextRow() ); // Now check for circular reference for(uint16 i=0; i<max_pool_id; ++i) { std::set<uint16> checkedPools; for(SearchMap::iterator poolItr = mPoolSearchMap.find(i); poolItr != mPoolSearchMap.end(); poolItr = mPoolSearchMap.find(poolItr->second)) { checkedPools.insert(poolItr->first); if(checkedPools.find(poolItr->second) != checkedPools.end()) { std::ostringstream ss; ss<< "The pool(s) "; for (std::set<uint16>::const_iterator itr=checkedPools.begin(); itr!=checkedPools.end(); ++itr) ss << *itr << " "; ss << "create(s) a circular reference, which can cause the server to freeze.\nRemoving the last link between mother pool " << poolItr->first << " and child pool " << poolItr->second; sLog.outErrorDb("%s", ss.str().c_str()); mPoolPoolGroups[poolItr->second].RemoveOneRelation(poolItr->first); mPoolSearchMap.erase(poolItr); --count; break; } } } sLog.outString(); sLog.outString( ">> Loaded %u pools in mother pools", count ); delete result; } }
void ExclusivePoolMgr::LoadFromDB() { QueryResult* result = WorldDatabase.Query("SELECT * FROM exclusive_pool"); if (!result) { sLog.outString(">> Table exclusive_pool is empty."); sLog.outString(); return; } BarGoLink bar(result->GetRowCount()); do { Field* fields = result->Fetch(); bar.step(); uint32 poolID = fields[0].GetUInt32(); time_t respawnTime = fields[1].GetUInt64(); m_pools[poolID] = ExclusivePool(poolID, respawnTime); } while (result->NextRow()); delete result; sLog.outBasic("Loaded %lu exclusive events...", m_pools.size()); QueryResult* result1 = WorldDatabase.Query("SELECT * FROM exclusive_pool_creature"); if (!result1) { sLog.outString(">> Table exclusive_pool_creature is empty."); sLog.outString(); } else { BarGoLink bar1(result1->GetRowCount()); uint32 counter = 0; do { Field* fields = result1->Fetch(); ++counter; bar1.step(); uint32 guid = fields[0].GetUInt32(); uint32 poolID = fields[1].GetUInt32(); uint32 groupID = fields[2].GetUInt32(); const CreatureData* pData = sObjectMgr.GetCreatureData(guid); if (pData) m_pools[poolID].m_objects[groupID].push_back(pData->GetObjectGuid(guid)); } while (result1->NextRow()); delete result1; sLog.outBasic("Loaded %u exclusive_pool_creatures...", counter); } QueryResult* result2 = WorldDatabase.Query("SELECT * FROM exclusive_pool_spot"); if (!result2) { sLog.outString(">> Table exclusive_pool_spot is empty."); sLog.outString(); } else { BarGoLink bar2(result2->GetRowCount()); uint32 counter = 0; do { Field* fields = result2->Fetch(); ++counter; bar2.step(); uint32 poolID = fields[1].GetUInt32(); uint32 mapID = fields[2].GetUInt32(); float x = fields[3].GetFloat(); float y = fields[4].GetFloat(); float z = fields[5].GetFloat(); float o = fields[6].GetFloat(); ExclusivePoolSpot spot = { mapID, x, y, z, o }; m_poolSpots[poolID].push_back(spot); } while (result2->NextRow()); delete result2; sLog.outBasic("Loaded %u exclusive_pool_spots...", counter); } QueryResult* result3 = WorldDatabase.Query("SELECT * FROM exclusive_pool_respawn"); if (!result3) { sLog.outString(">> Table exclusive_pool_spot is empty."); sLog.outString(); } else { BarGoLink bar3(result3->GetRowCount()); do { Field* fields = result3->Fetch(); bar3.step(); uint32 poolID = fields[0].GetUInt32(); time_t currentRespawnTime = fields[1].GetUInt64(); m_pools[poolID].currentRespawnTime = currentRespawnTime; } while (result3->NextRow()); delete result3; } }
int foo3 (int x) { union un u = bar2 (x); /* { dg-message "note: the ABI of passing union with long double has changed in GCC 4.4" } */ return u.i; }
void *Thread2(void *x) { bar2(); return NULL; }
int main() { bar1(); bar2(); return 0; }
void *Thread2(void *x) { bar2(); barrier_wait(&barrier); return NULL; }
void GameEvent::LoadFromDB() { QueryResult *result = WorldDatabase.Query("SELECT MAX(`entry`) FROM `game_event`"); if( !result ) { sLog.outString(">> Table game_event is empty."); sLog.outString(); return; } else { Field *fields = result->Fetch(); max_event_id = fields[0].GetUInt16(); delete result; } mGameEvent.resize(max_event_id + 1); result = WorldDatabase.Query("SELECT `entry`,UNIX_TIMESTAMP(`start`),UNIX_TIMESTAMP(`end`),`occurence`,`length`,`description` FROM `game_event`"); if( !result ) { mGameEvent.clear(); sLog.outString(">> Table game_event is empty:"); sLog.outString(); return; } uint32 count = 0; barGoLink bar( result->GetRowCount() ); do { count++; Field *fields = result->Fetch(); bar.step(); uint16 event_id = fields[0].GetUInt16(); GameEventData& pGameEvent = mGameEvent[event_id]; uint64 starttime = fields[1].GetUInt64(); pGameEvent.start = time_t(starttime); uint64 endtime = fields[2].GetUInt64(); pGameEvent.end = time_t(endtime); pGameEvent.occurence = fields[3].GetUInt32(); pGameEvent.length = fields[4].GetUInt32(); pGameEvent.description = fields[5].GetCppString(); } while( result->NextRow() ); sLog.outString(); sLog.outString( ">> Loaded %u game events", count ); delete result; mGameEventCreatureGuids.resize((max_event_id * 2) + 1); // 1 2 result = WorldDatabase.Query("SELECT `creature`.`guid`,`game_event_creature`.`event` " "FROM `creature` JOIN `game_event_creature` ON `creature`.`guid` = `game_event_creature`.`guid`"); count = 0; if( !result ) { barGoLink bar2(1); bar2.step(); sLog.outString(); sLog.outString(">> Loaded %u creatures in game events", count ); } else { barGoLink bar2( result->GetRowCount() ); do { Field *fields = result->Fetch(); bar2.step(); uint32 guid = fields[0].GetUInt32(); int16 event_id = fields[1].GetInt16(); if(max_event_id + event_id >= mGameEventCreatureGuids.size()) { sLog.outErrorDb("`game_event_creature` game event id (%i) is out of range compared to max event id in `game_event`",event_id); continue; } count++; GuidList& crelist = mGameEventCreatureGuids[max_event_id + event_id]; crelist.push_back(guid); } while( result->NextRow() ); sLog.outString(); sLog.outString( ">> Loaded %u creatures in game events", count ); delete result; } mGameEventGameobjectGuids.resize((max_event_id * 2) + 1); // 1 2 result = WorldDatabase.Query("SELECT `gameobject`.`guid`,`game_event_gameobject`.`event` " "FROM `gameobject` JOIN `game_event_gameobject` ON `gameobject`.`guid`=`game_event_gameobject`.`guid`"); count = 0; if( !result ) { barGoLink bar3(1); bar3.step(); sLog.outString(); sLog.outString(">> Loaded %u gameobjects in game events", count ); } else { barGoLink bar3( result->GetRowCount() ); do { Field *fields = result->Fetch(); bar3.step(); uint32 guid = fields[0].GetUInt32(); int16 event_id = fields[1].GetInt16(); if(max_event_id + event_id >= mGameEventGameobjectGuids.size()) { sLog.outErrorDb("`game_event_gameobject` game event id (%i) is out of range compared to max event id in `game_event`",event_id); continue; } count++; GuidList& golist = mGameEventGameobjectGuids[max_event_id + event_id]; golist.push_back(guid); } while( result->NextRow() ); sLog.outString(); sLog.outString( ">> Loaded %u gameobjects in game events", count ); delete result; } mGameEventModelEquip.resize(max_event_id + 1); // 0 1 2 result = WorldDatabase.Query("SELECT `creature`.`guid`,`game_event_model_equip`.`event`,`game_event_model_equip`.`modelid`," // 3 "`game_event_model_equip`.`equipment_id` " "FROM `creature` JOIN `game_event_model_equip` ON `creature`.`guid`=`game_event_model_equip`.`guid`"); count = 0; if( !result ) { barGoLink bar3(1); bar3.step(); sLog.outString(); sLog.outString(">> Loaded %u model/equipment changes in game events", count ); } else { barGoLink bar3( result->GetRowCount() ); do { Field *fields = result->Fetch(); bar3.step(); uint32 guid = fields[0].GetUInt32(); uint16 event_id = fields[1].GetUInt16(); if(event_id >= mGameEventModelEquip.size()) { sLog.outErrorDb("`game_event_model_equip` game event id (%u) is out of range compared to max event id in `game_event`",event_id); continue; } count++; ModelEquipList& equiplist = mGameEventModelEquip[event_id]; ModelEquip newModelEquipSet; newModelEquipSet.modelid = fields[2].GetUInt32(); newModelEquipSet.equipment_id = fields[3].GetUInt32(); newModelEquipSet.equipement_id_prev = 0; newModelEquipSet.modelid_prev = 0; equiplist.push_back(std::pair<uint32, ModelEquip>(guid, newModelEquipSet)); } while( result->NextRow() ); sLog.outString(); sLog.outString( ">> Loaded %u model/equipment changes in game events", count ); delete result; } mGameEventQuests.resize(max_event_id + 1); // 0 1 2 result = WorldDatabase.Query("SELECT `id`,`quest`,`event` FROM `game_event_creature_quest`"); count = 0; if( !result ) { barGoLink bar3(1); bar3.step(); sLog.outString(); sLog.outString(">> Loaded %u quests additions in game events", count ); } else { barGoLink bar3( result->GetRowCount() ); do { Field *fields = result->Fetch(); bar3.step(); uint32 id = fields[0].GetUInt32(); uint32 quest = fields[1].GetUInt32(); uint16 event_id = fields[2].GetUInt16(); if(event_id >= mGameEventQuests.size()) { sLog.outErrorDb("`game_event_creature_quest` game event id (%u) is out of range compared to max event id in `game_event`",event_id); continue; } count++; QuestRelList& questlist = mGameEventQuests[event_id]; questlist.push_back(QuestRelation(id, quest)); } while( result->NextRow() ); sLog.outString(); sLog.outString( ">> Loaded %u quests additions in game events", count ); delete result; } }