Author Topic: Getting creature speed  (Read 650 times)

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Getting creature speed
« on: January 23, 2016, 01:31:30 am »


               

I would like to know how to get a creature's total speed in an efficient manner. I am not talking about movement rate. I understand how to get the base movement rate. I really mean speed, as in how many meter's per second after factoring in all speed increases and decreases.


 


Is there a simple way to do this?  I am looking at using NWNX structs. But was hoping that I wouldn't be iterating over each speed increase and decrease effect with repeated NWNX calls in a NWScript loop. Is that the way to do this? Seems like there has to be a better way. And thats why I am asking.


 


Does anyone else do this? How do you do it?


 


Also... how do you figure out if a creature is running or walking?


 


 


-- or do i need to learn C++ to handle this? A bit above my skillset at the moment.


 


-- and also:


It seems that many users of NWNX out there have had to go through the trouble of documenting for themselves the specifics of what data is in each struct beyond the generalities of the GFF documentation that bioware has put out.  For example, the integer lists in each effect. What shows up at each index for the effects?  Figuring this crap out by trial and error is not fun. If you've gone through the pain, would you mind sharing the documentation?



               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Getting creature speed
« Reply #1 on: January 23, 2016, 09:31:46 am »


               

It should be stored as a single float value that is recursively updated. 


 


That is knowing what effects are in place does not indicate the order they were applied in, and is useless for determining the actual speed if monk levels are involved.


 


Not using NWNX myself, I can't tell where the value is stored, just that you are only looking for a single float.



               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Getting creature speed
« Reply #2 on: January 23, 2016, 04:15:27 pm »


               

Thanks. I was looking through the Aurora docs however and could not find this in any of the structs. I am not sure if I missed it, or if the order of the applied effects is stored in the order of the list of effects on the creature/pc. Thinking about it now, I suspect that the later is the case. I believe the list of effects on the creature is in order of application.



               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Getting creature speed
« Reply #3 on: January 23, 2016, 05:59:57 pm »


               


 I believe the list of effects on the creature is in order of application.




 


Still, even that won't include important information such as when an effect was removed.


 


Basically the formula for speed calculation (which is then multiplied by movement rate) is:


 


Product of all effects + monk/barbarian speed


 


However, in game, the effect application has a faulty recursive formula.  Instead of


 


New Speed = New Effect * (Old Speed - Monk speed) + Monk speed


 


it is rather


 


New Speed = New Effect * Old Speed + Monk Speed


 


This means that adding even one effect will over-represent the bonus that was intended.  Of course, removing a speed effect will cause all prior effects to be calculated by the intended formula with later effects going toward the recursive formula.


               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Getting creature speed
« Reply #4 on: January 23, 2016, 06:19:50 pm »


               

yeah, i read that. And I am almost certain that it simply reads the order of applied effects (which are still active).



               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Getting creature speed
« Reply #5 on: January 23, 2016, 06:29:53 pm »


               

NWN engine has three speed functions getwalkrate getrunrate and getmovementratefactor I got them in my modified version of nwnx_cool so its doable, but its notvery likely to appear anywhere - if you want this you would have to be able to compile your own plugin and then I could send you the code for this.


 


For now nwnx_structs is likely your best shot.


 


Oh and as for effect integers, cant serve. I ran into same problem obviously but never did any documentation I always simple learned with trial and error the integers for the effect I needed, and then applied in script and forget on it. In fact I dont even recall what I used it for.


 


The problem with windows nwnx is that its very scattered. Every developer has a different vision of how to do things. nwnx_funcs is bugged and crashing and leaking memory, nwnx_cool is no longer available and new terra plugins are all doing things slighly badly in my opinion. So most of us are using nwnx_cool with our own modifications. I was thinking about stepping out with new funcs plugin but Im not sure what should be there and how it should look like. Maybe in future.



               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Getting creature speed
« Reply #6 on: January 23, 2016, 06:54:49 pm »


               

Interesting stuff, Shadooow. But I don't need that code.


 


Once I realized how tricky this was to get, I decided to rethink what I was trying to do.  I am implementing a jump skill which operates the same as the PNP rules. A factor of that is creature's speed. But I realized that I can approximate the creature's speed from a number of factors without needing actual, and it works just fine.



               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Getting creature speed
« Reply #7 on: January 23, 2016, 09:59:56 pm »


               


But I realized that I can approximate the creature's speed from a number of factors without needing actual, and it works just fine.




 


Just to give a magnitude to the issue for monks by an example.


 


Let's define the speed multiplier as the number that would be multiplied by the base movement rate to get the actual speed.  The intended speed multiplier is what the game would calculate if a speed effect were applied and removed.


 


I have a level 18 monk (speed multiplier is 1.6) who equips a perma-haste item (speed multiplier is 3.0; intended speed multiplier is 2.1).  He then loots a dungeon and become lightly encumbered (speed multiplier is 2.85; intended speed multiplier is 1.725).  He then travels to a merchant to sell his equipment and loses his lightly encumbered status (speed multiplier is 2.1; intended speed multiplier is 2.1).  Seeing that he is now moving noticeably slower, he unequips and re-equips his perma-haste item (speed mulitiplier is 3.0; intended speed multiplier is 2.1).  If instead, he decided to remove his haste item right before he became lightly encumbered and then add it back on, he would be moving at a speed multiplier of 3.3 (intended speed multiplier is 1.725), which happens to be faster then what he would be moving at without the lightly encumbered status.


               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Getting creature speed
« Reply #8 on: January 23, 2016, 10:21:30 pm »


               

Yeah, thats crazy. Its not only crazy how buggy it is, but that you guys found out how it behaves.


 


I think we need a fix for that in NWNX_fixes. I don't know if niv or virusman are watching this but if they are.... '<img'> ...it would be a nice fix.



               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Getting creature speed
« Reply #9 on: January 23, 2016, 10:29:02 pm »


               


Yeah, thats crazy. Its not only crazy how buggy it is, but that you guys found out how it behaves.


 


I think we need a fix for that in NWNX_fixes. I don't know if niv or virusman are watching this but if they are.... '<img'> ...it would be a nice fix.




 


 


The fix is simple if you know where all the speed increases/decreases are to change (as well as using the OnEquip for the possibility of perma-haste as well as OnAcquire and OnUnAcqure for encumbrance measurements (detecting the stealth+detect mode is trickier)).  Whenever EffectHaste()/Slow()/MovementSpeedIncrease()/Decrease() is applied simply add one further line of code, delayed appropriately if needed, to add in a 0% movement speed increase for a trivial amount of time (like 0.01 seconds).  When the new effect expires the game will calculate speed according to its intended formula.



               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Getting creature speed
« Reply #10 on: January 24, 2016, 07:35:15 am »


               


 


I think we need a fix for that in NWNX_fixes. I don't know if niv or virusman are watching this but if they are.... '<img'> ...it would be a nice fix.




This hurts, you know my nwnx_patch contains more fixes than nwnx_fixes? Virusman made last addition into windows version of nwnx_fixes in 2009.


 


I will try to look into this.


               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Getting creature speed
« Reply #11 on: January 24, 2016, 01:32:07 pm »


               

Shadow, I am sorry that that hurts. I didn't mean it to.


 


The problem is that your patch only patches NWNX for windows. The best OS for NW Server is linux, and NWNX for linux is further developed than the windows branch. If you want more recognition for this work of yours you should get it ported to the linux version. I would be happy to see more fixes make it over.


 


Niv is still actively developing for NWNX linux and I've seen others checking stuff in on Git as well, including virusman. You could talk with them about your fixes. They would probably be happy to see your code integrated.



               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Getting creature speed
« Reply #12 on: January 24, 2016, 01:46:25 pm »


               


Niv is still actively developing for NWNX linux and I've seen others checking stuff in on Git as well, including virusman. You could talk with them about your fixes. They would probably be happy to see your code integrated.




I did but you know, they want this stuff to be in their plugin and I want this stuff to be in my plugin.


 


Actually I would like nwnx to be more centralized while other developers wants it as much decentralized as possible.


 


I guess Im too oldschool as the decentralization seems to be new way or work with all this forking and such.


               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Getting creature speed
« Reply #13 on: January 24, 2016, 03:40:41 pm »


               

I hope that you can figure out how to work together. I'd like to see this stuff.



               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Getting creature speed
« Reply #14 on: January 25, 2016, 12:43:35 pm »


               


Just to give a magnitude to the issue for monks by an example.


 


Let's define the speed multiplier as the number that would be multiplied by the base movement rate to get the actual speed.  The intended speed multiplier is what the game would calculate if a speed effect were applied and removed.


 


I have a level 18 monk (speed multiplier is 1.6) who equips a perma-haste item (speed multiplier is 3.0; intended speed multiplier is 2.1).  He then loots a dungeon and become lightly encumbered (speed multiplier is 2.85; intended speed multiplier is 1.725).  He then travels to a merchant to sell his equipment and loses his lightly encumbered status (speed multiplier is 2.1; intended speed multiplier is 2.1).  Seeing that he is now moving noticeably slower, he unequips and re-equips his perma-haste item (speed mulitiplier is 3.0; intended speed multiplier is 2.1).  If instead, he decided to remove his haste item right before he became lightly encumbered and then add it back on, he would be moving at a speed multiplier of 3.3 (intended speed multiplier is 1.725), which happens to be faster then what he would be moving at without the lightly encumbered status.




I managed to fix this.


 


Monk 21 speed 1.7 after haste (from any source) 2.2. But I dont know how it should behave further. What should happen after casting expeditious retreat? I have two possibilities either 2.2 (nothing) or 2.95. Or maybe totally different number?