void DGM_Effects_Table::_Populate()
{
    //first get list of all effects from dgmEffects table
    DBQueryResult *res = new DBQueryResult();
    ModuleDB::GetAllDgmEffects(*res);

    //counter
    MEffect * mEffectPtr;
    mEffectPtr = NULL;
    uint32 effectID;

	int total_effect_count = 0;
	int error_count = 0;

	//go through and populate each effect
    DBResultRow row;
    while( res->GetRow(row) )
    {
        effectID = row.GetInt(0);
        mEffectPtr = new MEffect(effectID);
		if( mEffectPtr->IsEffectLoaded() )
			m_EffectsMap.insert(std::pair<uint32, MEffect *>(effectID,mEffectPtr));
		else
			error_count++;

		total_effect_count++;
    }

	if( error_count > 0 )
		sLog.Error("DGM_Effects_Table::_Populate()","ERROR Populating the DGM_Effects_Table memory object: %u of %u effects failed to load!", error_count, total_effect_count);

    //cleanup
    delete res;
    res = NULL;
}
Пример #2
0
void ModuleEffects::_populate(uint32 typeID)
{
    //first get list of all of the effects associated with the typeID
    DBQueryResult *res = new DBQueryResult();
	TypeEffectsList * myTypeEffectsListPtr = sDGM_Type_Effects_Table.GetTypeEffectsList(typeID);

	// TODO: Instead of the above commented-out line, we need to get our list of effectIDs some other way NOT querying the DB,
	// in other words, using the new sDGM_Type_Effects_Table object, then take that list of effectIDs to loop through and create
	// MEffect objects with each one.

	std::map<uint32,uint32> effectsList;
	myTypeEffectsListPtr->GetEffectsList(&effectsList);

    //counter
    MEffect * mEffectPtr;
    mEffectPtr = NULL;
    m_defaultEffect = NULL;     // Set this to NULL until the default effect is found, if there is any
    uint32 effectID;
    uint32 isDefault;

    //go through and find each effect, then add pointer to effect to our own map
	std::map<uint32,uint32>::iterator cur, end;
	cur = effectsList.begin();
	end = effectsList.end();
    for(; cur != end; cur++)
    {
		effectID = (*cur).first;
		mEffectPtr = new MEffect(effectID);

		if( mEffectPtr != NULL )
		{
			if( mEffectPtr->IsEffectLoaded() )
			{
				isDefault = (*cur).second;
				switch( effectID )
				{
					case 11:    // loPower
					case 12:    // hiPower
					case 13:    // medPower
						// We do not need to make MEffect objects these effectIDs, since they do nothing
						delete mEffectPtr;
						mEffectPtr = NULL;
						break;

					default:
						mEffectPtr = sDGM_Effects_Table.GetEffect(effectID);
						break;
				}

				// Just in case our 'mEffectPtr' gets deleted above for certain cases, let's not proceed further lest we crash!
				if( mEffectPtr != NULL )
				{
					if( isDefault > 0 )
						m_defaultEffect = mEffectPtr;

					// This switch is assuming that all entries in 'dgmEffectsInfo' for this effectID are applied during the same module state,
					// which should really be the case anyway, for every effectID, so we just check the list of attributes
					// that are modified by this effect for which module state during which the effect is active:
					uint32 moduleStateWhenEffectApplied = mEffectPtr->GetModuleStateWhenEffectApplied();
					if( moduleStateWhenEffectApplied == MOD_UNFITTED )
						sLog.Error("ModuleEffects::_populate()", "Illegal value '%u' obtained from the 'effectAppliedInState' field of the 'dgmEffectsInfo' table", mEffectPtr->GetModuleStateWhenEffectApplied());

					if( moduleStateWhenEffectApplied & MOD_OFFLINE )
						;	// nothing

					if( moduleStateWhenEffectApplied & MOD_ONLINE )
						m_OnlineEffects.insert(std::pair<uint32, MEffect *>(effectID,mEffectPtr));

					if( moduleStateWhenEffectApplied & MOD_ACTIVATED )
						m_ActiveEffects.insert(std::pair<uint32, MEffect *>(effectID,mEffectPtr));

					if( moduleStateWhenEffectApplied & MOD_OVERLOADED )
						m_OverloadEffects.insert(std::pair<uint32, MEffect *>(effectID,mEffectPtr));

					if( moduleStateWhenEffectApplied & MOD_GANG )
						m_GangEffects.insert(std::pair<uint32, MEffect *>(effectID,mEffectPtr));

					if( moduleStateWhenEffectApplied & MOD_FLEET )
						m_FleetEffects.insert(std::pair<uint32, MEffect *>(effectID,mEffectPtr));

					if( moduleStateWhenEffectApplied & MOD_DEACTIVATING )
						;	// nothing
				}
			}
        }
    }

    //cleanup
    delete res;
    res = NULL;
}