Fixed bug that was causing population to go negative. It was due to a unit being killed by multiple enemies in the same frame, which led to multiple calls of the death event handler. The fix is twofold: First, kill() only calls the event handler the first time the unit is killed. Second, damage() (in JS), which apart from killing things also loots them, makes sure that the unit is not already being destroyed. This latter fix is to ensure that we don't get a huge amount of loot by simply attacking a low-HP unit with many soldiers simultaneously, so they kill it in the same frame.

This was SVN commit r6276.
This commit is contained in:
Matei
2008-07-24 05:50:45 +00:00
parent 75a9b2f357
commit d0c6805725
4 changed files with 13 additions and 4 deletions
+1 -3
View File
@@ -57,6 +57,7 @@ void CEntity::ScriptingInit()
AddMethod<jsval_t, &CEntity::TerminateOrder>( "terminateOrder", 1 );
AddMethod<bool, &CEntity::Kill>( "kill", 0 );
AddMethod<bool, &CEntity::IsIdle>( "isIdle", 0 );
AddMethod<bool, &CEntity::IsDestroyed>( "isDestroyed", 0 );
AddMethod<bool, &CEntity::HasClass>( "hasClass", 1 );
AddMethod<jsval_t, &CEntity::GetSpawnPoint>( "getSpawnPoint", 1 );
AddMethod<jsval_t, &CEntity::AddAura>( "addAura", 3 );
@@ -364,9 +365,6 @@ bool CEntity::Order( JSContext* cx, uintN argc, jsval* argv, CEntityOrder::EOrde
bool CEntity::Kill( JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv) )
{
CEventDeath evt;
DispatchEvent( &evt );
Kill(true);
return( true );