Skip to content

Commit

Permalink
Split dgmEffectsInfo table into two with a new table dgmEffectsAction…
Browse files Browse the repository at this point in the history
…s so there weren't any unutilized fields in the previous single table design by having to add a few new fields. dgmEffectsInfo contains each attribute modified by an effect and how to modify/unmodify it. dgmEffectsActions table contains one row per effect on which state it is active, is it subject to stacking penalties, is it going to nullify an effect that went active in the Online state, etc. SQL file updated to create both tables. ModuleDB.h/.cpp and ModuleDefs.h and ModuleEffects.h/.cpp all modified to make use of these two tables and pull data from them to be stored in in-memory objects for use by the ModuleManager later. Added checking and setting for CPU load and Power load attributes in the Ship class, just in case the dgmTypeAttributes table does not contain those for one or more ship types. Enabled Armor Hardener group to be a basic PassiveModule in the ModuleFactory.h file.
  • Loading branch information
aknorjaden committed Mar 13, 2012
1 parent 3e0ae9b commit 8416909
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 36 deletions.
1 change: 1 addition & 0 deletions include/eve-server/ship/Modules/ModuleDB.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class ModuleDB : public ServiceDB

static void GetDgmEffects(uint32 effectID, DBQueryResult &res);
static void GetDgmEffectsInfo(uint32 effectID, DBQueryResult &res);
static void GetDgmEffectsActions(uint32 effectID, DBQueryResult &res);
static void GetDgmTypeEffectsInformation(uint32 typeID, DBQueryResult &res);

};
Expand Down
52 changes: 41 additions & 11 deletions include/eve-server/ship/Modules/ModuleDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,21 @@ enum ModuleEffectTargets
// *** use these values to decode the 'effectApplicationType' field of the 'dgmEffectsInfo' database table
enum ModuleApplicationTypes
{
EFFECT_ONLINE_MAINTAIN, // applied by PASSIVE or ACTIVE modules where an effect is maintained; means the effect takes effect on the
// target (see below) upon entering the ONLINE state, then reversed when going out of ONLINE state
EFFECT_ACTIVE_MAINTAIN, // applied by ACTIVE modules where an effect is maintained; means the effect takes effect on the
// target (see below) upon entering the ACTIVATE state, then reversed when going out of ACTIVATE state
EFFECT_ACTIVE_CONSUME // applied by ACTIVE modules where an effect is applied cumulatively on each cycle; means the effect takes
}; // effect on the target (see below) one extra time when in ACTIVATE state after each CYCLE duration expires

// These are the methods by which module effects are applied to the designated target:
// *** use these values to decode the 'stackingPenaltyApplied' field of the 'dgmEffectsInfo' database table
enum ModuleStackingPenaltyState
{
NO_PENALTY,
PENALTY
};

//this may or may not be redundant...idk
enum ModulePowerLevel
{
Expand All @@ -100,15 +110,19 @@ enum ModulePowerLevel
};

//calculation types
// *** use these values to decode the 'calculationTypeID' and the 'reverseCalculationTypeID' fields of the 'dgmEffectsInfo' database table
enum EVECalculationType
{
NONE,
AUTO,
ADD,
SUBTRACT,
DIVIDE,
MULTIPLY,
ADD_PERCENT,
REV_ADD_PERCENT,
SUBTRACT_PERCENT,
REV_SUBTRACT_PERCENT,
ADD_AS_PERCENT,
SUBTRACT_AS_PERCENT
//more will show up, im sure
Expand Down Expand Up @@ -141,17 +155,29 @@ static EvilNumber AddPercent(EvilNumber &val1, EvilNumber &val2)
return val1 + ( val1 * val2 );
}

static EvilNumber AddAsPercent(EvilNumber &val1, EvilNumber &val2)
static EvilNumber ReverseAddPercent(EvilNumber &val1, EvilNumber &val2)
{
EvilNumber val3 = 100;
return val1 + ( val1 * (val2 / val3) );
EvilNumber val3 = 1;
return val1 / (val3 + val2);
}

static EvilNumber SubtractPercent(EvilNumber &val1, EvilNumber &val2)
{
return val1 - ( val1 * val2 );
}

static EvilNumber ReverseSubtractPercent(EvilNumber &val1, EvilNumber &val2)
{
EvilNumber val3 = 1;
return val1 / ( val3 - val2 );
}

static EvilNumber AddAsPercent(EvilNumber &val1, EvilNumber &val2)
{
EvilNumber val3 = 100;
return val1 + ( val1 * (val2 / val3) );
}

static EvilNumber SubtractAsPercent(EvilNumber &val1, EvilNumber &val2)
{
EvilNumber val3 = 1;
Expand All @@ -164,14 +190,18 @@ static EvilNumber CalculateNewAttributeValue(EvilNumber attrVal, EvilNumber attr
{
switch(type)
{
case ADD : return Add(attrVal, attrMod);
case SUBTRACT : return Subtract(attrVal, attrMod);
case DIVIDE : return Divide(attrVal, attrMod);
case MULTIPLY : return Multiply(attrVal, attrMod);
case ADD_PERCENT : return AddPercent(attrVal, attrMod);
case ADD_AS_PERCENT : return AddAsPercent(attrVal, attrMod);
case SUBTRACT_PERCENT : return SubtractPercent(attrVal, attrMod);
case SUBTRACT_AS_PERCENT : return SubtractAsPercent(attrVal, attrMod);
case NONE : return attrVal;
case AUTO : return attrVal; // AUTO NOT SUPPORTED AT THIS TIME !!!
case ADD : return Add(attrVal, attrMod);
case SUBTRACT : return Subtract(attrVal, attrMod);
case DIVIDE : return Divide(attrVal, attrMod);
case MULTIPLY : return Multiply(attrVal, attrMod);
case ADD_PERCENT : return AddPercent(attrVal, attrMod);
case REV_ADD_PERCENT : return ReverseAddPercent(attrVal, attrMod);
case SUBTRACT_PERCENT : return SubtractPercent(attrVal, attrMod);
case REV_SUBTRACT_PERCENT : return ReverseSubtractPercent(attrVal, attrMod);
case ADD_AS_PERCENT : return AddAsPercent(attrVal, attrMod);
case SUBTRACT_AS_PERCENT : return SubtractAsPercent(attrVal, attrMod);
}

sLog.Error("CalculateNewAttributeValue", "Unknown EveCalculationType used");
Expand Down
20 changes: 14 additions & 6 deletions include/eve-server/ship/Modules/ModuleEffects.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,19 @@ class MEffect
uint32 GetNpcActivationChanceAttributeID() { return (m_EffectID == 0) ? 0 : m_NpcActivationChanceAttributeID; }
uint32 GetFittingUsageChanceAttributeID() { return (m_EffectID == 0) ? 0 : m_FittingUsageChanceAttributeID; }

//accessors for the effects targetAttributeID, sourceAttributeID and calculation type
//accessors for the effects targetAttributeID, sourceAttributeID and calculation type:
uint32 GetSizeOfAttributeList() { return (m_EffectID == 0) ? 0 : m_numOfIDs; }
uint32 GetTargetAttributeID(uint32 index) { return (m_EffectID == 0) ? 0 : m_TargetAttributeIDs[index]; }
uint32 GetSourceAttributeID(uint32 index) { return (m_EffectID == 0) ? 0 : m_SourceAttributeIDs[index]; }
EVECalculationType GetCalculationType(uint32 index) { return (m_EffectID == 0) ? (EVECalculationType)0 : (EVECalculationType)m_CalculationTypeIDs[index];}
EVECalculationType GetReverseCalculationType(uint32 index) { return (m_EffectID == 0) ? (EVECalculationType)0 : (EVECalculationType)m_ReverseCalculationTypeIDs[index];}
uint32 GetModuleStateWhenEffectApplied(uint32 index) { return (m_EffectID == 0) ? 0 : m_EffectAppliedWhenIDs[index]; }
uint32 GetTargetTypeToWhichEffectApplied(uint32 index) { return (m_EffectID == 0) ? 0 : m_EffectAppliedTargetIDs[index]; }

uint32 GetModuleStateWhenEffectApplied(uint32 index) { return (m_EffectID == 0) ? 0 : m_EffectAppliedWhenID; }
uint32 GetTargetTypeToWhichEffectApplied(uint32 index) { return (m_EffectID == 0) ? 0 : m_EffectAppliedTargetID; }
uint32 GetEffectApplicationType(uint32 index) { return (m_EffectID == 0) ? 0 : m_EffectApplicationTypeID; }
uint32 GetStackingPenaltyApplied(uint32 index) { return (m_EffectID == 0) ? 0 : m_StackingPenaltyAppliedID; }
uint32 GetNullifyOnlineEffectEnable(uint32 index) { return (m_EffectID == 0) ? 0 : m_NullifyOnlineEffectEnable; }
uint32 GetNullifiedOnlineEffectID(uint32 index) { return (m_EffectID == 0) ? 0 : m_NullifiedOnlineEffectID; }

private:
void _Populate(uint32 effectID);
Expand Down Expand Up @@ -109,9 +114,12 @@ class MEffect
int * m_SourceAttributeIDs;
int * m_CalculationTypeIDs;
int * m_ReverseCalculationTypeIDs;
int * m_EffectAppliedWhenIDs;
int * m_EffectAppliedTargetIDs;
int * m_EffectApplicationTypeIDs;
int m_EffectAppliedWhenID;
int m_EffectAppliedTargetID;
int m_EffectApplicationTypeID;
int m_StackingPenaltyAppliedID;
int m_NullifyOnlineEffectEnable;
int m_NullifiedOnlineEffectID;
};

//class contained by all modules that is populated on construction of the module
Expand Down
2 changes: 1 addition & 1 deletion include/eve-server/ship/Modules/ModuleFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ static GenericModule* ModuleFactory(InventoryItemRef item, ShipRef ship)
case EVEDB::invGroups::Armor_Coating: return (new PassiveModule(item, ship)); break;
case EVEDB::invGroups::Armor_Repair_Projector: return NULL; // Active
case EVEDB::invGroups::Armor_Plating_Energized: return (new PassiveModule(item, ship)); break;
case EVEDB::invGroups::Armor_Hardener: return NULL; // Active
case EVEDB::invGroups::Armor_Hardener: return (new ActiveModule(item, ship)); break; // Active
case EVEDB::invGroups::Armor_Reinforcer: return (new PassiveModule(item, ship)); break;
case EVEDB::invGroups::Remote_Hull_Repairer: return NULL; // Active
case EVEDB::invGroups::Expanded_Cargohold: return (new PassiveModule(item, ship)); break;
Expand Down
26 changes: 21 additions & 5 deletions sql/ofic-updates/dgmEffectsInfo.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,41 @@ SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
-- Table structure for table `dgmEffectsInfo`
--

DROP TABLE IF EXISTS `dgmEffectsInfo`;
CREATE TABLE IF NOT EXISTS `dgmEffectsInfo` (
`effectID` int(11) NOT NULL,
`targetAttributeID` int(11) NOT NULL,
`sourceAttributeID` int(11) NOT NULL,
`calculationTypeID` int(11) NOT NULL,
`reverseCalculationTypeID` int(11) NOT NULL,
`reverseCalculationTypeID` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `dgmEffectsInfo`
--



--
-- Table structure for table `dgmEffectsActions`
--

DROP TABLE IF EXISTS `dgmEffectsActions`;
CREATE TABLE IF NOT EXISTS `dgmEffectsActions` (
`effectID` int(11) NOT NULL,
`effectAppliedInState` int(11) NOT NULL,
`effectAppliedTo` int(11) NOT NULL,
`effectApplicationType` int(11) NOT NULL,
`stackingPenaltyApplied` int(11) NOT NULL,
`nullifyOnlineEffect` int(11) NOT NULL,
`nullifiedOnlineEffectID` int(11) NOT NULL,
PRIMARY KEY (`effectID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `dgmEffectsInfo`
-- Dumping data for table `dgmEffectsActions`
--

INSERT INTO `dgmEffectsInfo` (`effectID`, `targetAttributeID`, `sourceAttributeID`, `calculationTypeID`, `reverseCalculationTypeID`, `effectApplied`, `effectAppliedTo`) VALUES
(1959, 4, 796, 1, 2, 0, 1),
(2837, 265, 1159, 1, 2, 0, 1);

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
Expand Down
21 changes: 18 additions & 3 deletions src/eve-server/ship/Modules/ModuleDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@ void ModuleDB::GetDgmEffectsInfo(uint32 effectID, DBQueryResult &res)
" sourceAttributeID, "
" calculationTypeID, "
" reverseCalculationTypeID, "
" effectAppliedInState, "
" effectAppliedTo, "
" effectApplicationType "
" FROM dgmEffectsInfo "
" WHERE effectID = '%u' ",
effectID))
Expand All @@ -84,6 +81,24 @@ void ModuleDB::GetDgmEffectsInfo(uint32 effectID, DBQueryResult &res)
}
}

void ModuleDB::GetDgmEffectsActions(uint32 effectID, DBQueryResult &res)
{
if( !sDatabase.RunQuery(res,
" SELECT "
" effectAppliedInState, "
" effectAppliedTo, "
" effectApplicationType, "
" stackingPenaltyApplied, "
" nullifyOnlineEffect, "
" nullifiedOnlineEffectID, "
" FROM dgmEffectsActions "
" WHERE effectID = '%u' ",
effectID))
{
_log(DATABASE__ERROR, "Error in query: %s", res.error.c_str());
}
}

void ModuleDB::GetDgmTypeEffectsInformation(uint32 typeID, DBQueryResult &res)
{
if( !sDatabase.RunQuery(res,
Expand Down
34 changes: 24 additions & 10 deletions src/eve-server/ship/Modules/ModuleEffects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ void MEffect::_Populate(uint32 effectID)
DBQueryResult *res = new DBQueryResult();
ModuleDB::GetDgmEffects(effectID, *res);

// First, get all general info on this effectID from the dgmEffects table:
DBResultRow row1;
if( !res->GetRow(row1) )
sLog.Error("MEffect","Could not populate effect information for effectID: %u", effectID);
sLog.Error("MEffect","Could not populate effect information for effectID: %u from the 'dgmEffects' table", effectID);
else
{
//get all the data from the query
Expand Down Expand Up @@ -95,21 +96,17 @@ void MEffect::_Populate(uint32 effectID)
m_FittingUsageChanceAttributeID = row1.GetInt(25);
}

//next get the info from the dgmEffectsInfo table
// Next, get the info from the dgmEffectsInfo table:
ModuleDB::GetDgmEffectsInfo(effectID, *res);

DBResultRow row2;

//initialize the new tables
// Initialize the new tables
m_TargetAttributeIDs = new int[res->GetRowCount()];
m_SourceAttributeIDs = new int[res->GetRowCount()];
m_CalculationTypeIDs = new int[res->GetRowCount()];
m_ReverseCalculationTypeIDs = new int[res->GetRowCount()];
m_EffectAppliedWhenIDs = new int[res->GetRowCount()];
m_EffectAppliedTargetIDs = new int[res->GetRowCount()];
m_EffectApplicationTypeIDs = new int[res->GetRowCount()];

//counter
int count = 0;

while( res->GetRow(row2) )
Expand All @@ -118,14 +115,31 @@ void MEffect::_Populate(uint32 effectID)
m_SourceAttributeIDs[count] = row2.GetInt(1);
m_CalculationTypeIDs[count] = row2.GetInt(2);
m_ReverseCalculationTypeIDs[count] = row2.GetInt(3);
m_EffectAppliedWhenIDs[count] = row2.GetInt(4);
m_EffectAppliedTargetIDs[count] = row2.GetInt(5);
m_EffectApplicationTypeIDs[count] = row2.GetInt(6);
count++;
}

if( count == 0 )
sLog.Error("MEffect","Could not populate effect information for effectID: %u from the 'dgmEffectsInfo' table as the SQL query returned ZERO rows", effectID);

m_numOfIDs = count;

// Finally, get the info for this effectID from the dgmEffectsActions table:
ModuleDB::GetDgmEffectsActions(effectID, *res);

DBResultRow row3;

if( !(res->GetRow(row3)) )
sLog.Error("MEffect","Could not populate effect information for effectID: %u from 'dgmEffectsActions table", effectID);
else
{
m_EffectAppliedWhenID = row3.GetInt(0);
m_EffectAppliedTargetID = row3.GetInt(1);
m_EffectApplicationTypeID = row3.GetInt(2);
m_StackingPenaltyAppliedID = row3.GetInt(3);
m_NullifyOnlineEffectEnable = row3.GetInt(4);
m_NullifiedOnlineEffectID = row3.GetInt(5);
}

delete res;
res = NULL;
}
Expand Down
6 changes: 6 additions & 0 deletions src/eve-server/ship/Ship.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ ShipRef Ship::Spawn(ItemFactory &factory,
// Warp Speed Multiplier
if( !(sShipRef.get()->HasAttribute(AttrWarpSpeedMultiplier)) )
sShipRef.get()->SetAttribute(AttrWarpSpeedMultiplier, 1.0f);
// CPU Load of the ship (new ships have zero load with no modules fitted, of course):
if( !(sShipRef.get()->HasAttribute(AttrCpuLoad)) )
sShipRef.get()->SetAttribute(AttrCpuLoad, 0);
// Power Load of the ship (new ships have zero load with no modules fitted, of course):
if( !(sShipRef.get()->HasAttribute(AttrPowerLoad)) )
sShipRef.get()->SetAttribute(AttrPowerLoad, 0);

return sShipRef;
}
Expand Down

0 comments on commit 8416909

Please sign in to comment.