Jump to content

Regen health


Recommended Posts

Hello everyone this is my first post here

please help me, i'm not a programmer, i need some suggestion here

i tried to enable health regen based on TeritoryDecay.js

there is some mistake but i dont know how to fix it

i added this in to health.js


// begin regen
// Based on TeritoryDecay
// How: true if own teritory false outside own teritory
Health.prototype.IsConnected = function()
{
var cmpPosition = Engine.QueryInterface(this.entity, IID_Position);
if (!cmpPosition || !cmpPosition.IsInWorld())
return false;
var cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership);
if (!cmpOwnership)
return false;

// Prevent special gaia buildings from Regening (e.g. fences, ruins)
//if (cmpOwnership.GetOwner() == 0)
//return true;
var cmpTerritoryManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TerritoryManager);
if (!cmpTerritoryManager)
return false;
var pos = cmpPosition.GetPosition2D();
var tileOwner = cmpTerritoryManager.GetOwner(pos.x, pos.y);
if (tileOwner != cmpOwnership.GetOwner())
return false;
// TODO: this should probably use the same territory restriction
// logic as BuildRestrictions, to handle allies etc
return cmpTerritoryManager.IsConnected(pos.x, pos.y);
};
Health.prototype.UpdateRegenState = function()
{
var damage = this.GetMaxHitpoints() - this.GetHitpoints();
var connected = this.IsConnected();
if (!connected && !this.timer && !damage)
{
// Start Regening
var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer);
this.timer = cmpTimer.SetInterval(this.entity, IID_Health, "Regen", 1000, 1000, {});
}
else if (connected && this.timer)
{
// Stop Regening
var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer);
cmpTimer.CancelTimer(this.timer);
this.timer = undefined;
}
};
Health.prototype.OnTerritoriesChanged = function(msg)
{
this.UpdateRegenState();
};
Health.prototype.OnOwnershipChanged = function(msg)
{
this.UpdateRegenState();
};
Health.prototype.Regen = function()
{
//var hitpoints = this.hitpoints;
if (!this.hitpoints)
return; // error
this.Increase(+this.template.RegenRate);
};
// end regen

how to implement this condition, true when in own teritory and false when outside own teritory

i need guide explaining in IsConnected function

sorry for my bad english and sorry if i have to much ask, thanks before

Link to comment
Share on other sites

Sorry for late reply all, im not regulary connected

@Quantumstate: i test on miletus map, regen only happen with helleness but not for rome

and it happens in and outside his own teritory line

i think its happen when we have teritory then we're able to regen, if not then unable to regen

what i expect is regen only happen when units possition stand in inside their own teritory like logic in BuildRestriction.js

i have no idea about cmpPosition, cmpOwnership, cmpTerritoryManager in IsConnected function if anyone can explain i'll be gratefull

@Pedro: no, error text is from TeritoryDecay.js

Link to comment
Share on other sites

You want health to regen when units are in their own territory. Your if statement seems to do the opposite. You should regen health when IsConnected returns true.

0 A.D. has lots of components which each do different tasks so cmpPosition is the position component etc. The IsConnected function first checks that all of the components exist, then checks if the territory is owned by the player that the unit belong to then checks that the territory is connected to a Civil Centre. If you destroy a civil centre in the game you will see that the territory border around the nearby buildings starts flashing, this means the territory is not connected and buildings will start to decay.

Another problem is that you only update the timer when territories or ownership changes. This means that the timer will not be updated when moving units around. This doesn't matter for buildings of course since they cannot move.

Link to comment
Share on other sites

You want health to regen when units are in their own territory. Your if statement seems to do the opposite. You should regen health when IsConnected returns true.

0 A.D. has lots of components which each do different tasks so cmpPosition is the position component etc. The IsConnected function first checks that all of the components exist, then checks if the territory is owned by the player that the unit belong to then checks that the territory is connected to a Civil Centre. If you destroy a civil centre in the game you will see that the territory border around the nearby buildings starts flashing, this means the territory is not connected and buildings will start to decay.

Another problem is that you only update the timer when territories or ownership changes. This means that the timer will not be updated when moving units around. This doesn't matter for buildings of course since they cannot move.

Thanks for quick reply, ok i'll try it later, now i'm going to update my 0ad first

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...