SFTtech / nyan

Typesafe hierarchical key-value database with inheritance and dynamic patching :smiley_cat:
Other
208 stars 29 forks source link

Defer(?) operations #72

Open MaanooAk opened 4 years ago

MaanooAk commented 4 years ago

Example:


Archer(Unit):
    firerate : float = 0

Crossbowman(Archer)
    firerate = 12

Longbowman(Archer):
    firerate = 10

ThumbRing(Technology):
    ThumbRing1<Longbowman>():
        firerate *= 1.2
    ThumbRing2<Crossbowman>():
        firerate *= 1.2

    patches = {ThumbRing1, ThumbRing2}

This is the correct solution so far, am I wrong ?

If you try to do this:

ThumbRing<Archer>(Technology):
    firerate *= 1.2

Then the stack of calculation would be:

firerate = 0
firerate *= 1.2
firerate = 10
  V
firerate = 10

However there could be something like defer which would move the operation to the end:

ThumbRing<Archer>(Technology):
    firerate defer *= 1.2

And then there would be two stucks:

firerate = 0
defer firerate *= 1.2
firerate = 10
                                   V       
firerate = 0
firerate = 10
firerate *= 1.2
                                   V                   
firerate = 10
firerate *= 1.2
                                   V
firerate = 12
TheJJ commented 4 years ago

Good idea, that could be a solution to something we worked around with the API itself (through a bonus system that is applied "last" in the stack in the c++ engine implementation).

This defer flag even works with inherited patches: They add their calculation part to the "end" of the stack one after the other starting at the top (as this is how the patch application is chained).

We have to think a bit about unforseen consequences, although just now it seems like a great idea :smile: . We should evaluate other syntactical variants of this though, especially in sight of future directions the nyan language may head.