lazarus Posted May 16, 2012 Report Share Posted May 16, 2012 Hello everyone this is my first post hereplease help me, i'm not a programmer, i need some suggestion herei tried to enable health regen based on TeritoryDecay.jsthere is some mistake but i dont know how to fix iti added this in to health.js// begin regen// Based on TeritoryDecay// How: true if own teritory false outside own teritoryHealth.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 etcreturn 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; // errorthis.Increase(+this.template.RegenRate);};// end regenhow to implement this condition, true when in own teritory and false when outside own teritoryi need guide explaining in IsConnected functionsorry for my bad english and sorry if i have to much ask, thanks before Quote Link to comment Share on other sites More sharing options...
quantumstate Posted May 16, 2012 Report Share Posted May 16, 2012 The code generally seems to make sense. You say you made a mistake, can you give more details about what you expected to happen and what actually happened? Quote Link to comment Share on other sites More sharing options...
Pedro Falcão Posted May 16, 2012 Report Share Posted May 16, 2012 In one of the last lines, there is a commented "error". Is that where you think the mistake might be? Quote Link to comment Share on other sites More sharing options...
Zeta1127 Posted May 17, 2012 Report Share Posted May 17, 2012 Shouldn't there be brackets for that last if statement? Quote Link to comment Share on other sites More sharing options...
quantumstate Posted May 17, 2012 Report Share Posted May 17, 2012 Shouldn't there be brackets for that last if statement?The 0 A.D. coding style for components doesn't use the {} for an if() with a single statement. Quote Link to comment Share on other sites More sharing options...
lazarus Posted May 17, 2012 Author Report Share Posted May 17, 2012 Sorry for late reply all, im not regulary connected@Quantumstate: i test on miletus map, regen only happen with helleness but not for romeand it happens in and outside his own teritory linei think its happen when we have teritory then we're able to regen, if not then unable to regenwhat i expect is regen only happen when units possition stand in inside their own teritory like logic in BuildRestriction.jsi 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 Quote Link to comment Share on other sites More sharing options...
quantumstate Posted May 17, 2012 Report Share Posted May 17, 2012 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. Quote Link to comment Share on other sites More sharing options...
lazarus Posted May 17, 2012 Author Report Share Posted May 17, 2012 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.