Comparing to values

Well, i got a pretty big program (a world of warcraft server)

I dont know really where i should begin.

Anyways, im having a problem with a function im trying to write.
Im trying to add a damage/healing "map" to all players, so you can analyse who did damage to who and who did healing to who etc...

And i got this function:

1
2
3
4
5
6
7
8
void Player::DamagedOrHealed(ObjectGuid guid, uint32 damage, uint32 heal)
{
	DamageHealData *data = NULL;
	if (!data = m_DamagersAndHealers[guid])
		m_DamagersAndHealers[guid] = new DamageHealData();
	data->damage += damage;
	data->healing += heal;
}


and this struct:
1
2
3
4
5
struct DamageHealData
{
	DamageHealData() : damage(0), healing(0) { }
	uint32 damage; uint32 healing;
};


and this declarations inside the player class

1
2
		std::map<ObjectGuid, DamageHealData*> m_DamagersAndHealers;
		void DamagedOrHealed(ObjectGuid guid, uint32 damage, uint32 heal);


And when i try to compile i get this error:

2>..\..\src\game\Player.cpp(19259) : error C2106: '=' : left operand must be l-value


from this line:
if (!data = m_DamagersAndHealers[guid])


I dont know if this info is enough for you big boys, but i cannot solve the riddle, if you need more info / the entire source its on http://github.com/kalimdorgaming/server

and the code/function is something i got from a forum (with a sloght modification) and i can post it here so you can see it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Add this in Player.h 
struct DamageHealData
{
	DamageHealData() : damage(0), healing(0) { }
	uint32 damage; uint32 healing;
};
// Add this to Player class
std::map<uint64, DamageHealData*> m_DamagersAndHealers;
//Unit::DealDamage
if (GetTypeId() == TYPEID_PLAYER && pVictim->GetTypeId() == TYPEID_PLAYER)
	((Player*)pVictim)->DamagedOrHealed(GetGUID(), damage, 0);
// Unit::DealHeal
if (GetTypeId() == TYPEID_PLAYER && pVictim->GetTypeId() == TYPEID_PLAYER)
	((Player*)pVictim)->DamagedOrHealed(GetGUID(), 0, addhealth);
// Unit::ClearInCombat
if (GetTypeId() == TYPEID_PLAYER)
{
	Player *p = ((Player*)this);
	for (std::map<uint64, DamageHealData*>::iterator itr = p->m_DamagersAndHealers.begin(); itr != p->m_DamagersAndHealers.end(); ++itr)
		delete itr->second; p->m_DamagersAndHealers.clear();
}
void Player::DamagedOrHealed(uint64 guid, uint32 damage, uint32 heal)
{
	DamageHealData *data = NULL;
	if (!data = m_DamagersAndHealers[guid])
	m_DamagersAndHealers[guid] = new DamageHealData();
	data->damage += damage;
	data->healing += heal;
}
// Example
for (std::map<uint64, DamageHealData*>::iterator itr = m_DamagersAndHealers.begin(); itr != m_DamagersAndHealers.end(); ++itr)
{
	if (itr->second->damage > itr->second->healing)
		sLog->outString("Player with GUID %u is damager");
	else
		sLog->outString("Player with GUID %u is healer");
}


since rescent code changes the uint64 should be "ObjectGuid" i think, and that is what im using as you see.

EDIT: The = maby should be a == im not sure, but then i get this output:
1
2
3
2>..\..\src\game\Player.cpp(19259) : error C2446: '==' : no conversion from 'DamageHealData *' to 'int'
2>        There is no context in which this conversion is possible
2>..\..\src\game\Player.cpp(19259) : error C2040: '==' : 'int' differs in levels of indirection from 'DamageHealData *'


thanks in advance

- Carl Hjerpe
Last edited on
1
2
DamageHealData *data = NULL;
	if (!data = m_DamagersAndHealers[guid])


data is NULL. Always. Always and always because you just set it to that. So what exactly are you trying to say about m_DamagersAndHealers[guid]? Did you mean this:

1
2
if (m_DamagersAndHealers[guid] == NULL)
  	m_DamagersAndHealers[guid] = new DamageHealData();
Last edited on
Just tested that, and its compiling, now im going to test it running

Thanks alot!!!!

(Feedback is coming)
Topic archived. No new replies allowed.