top of page

CSS: Customizable Spell System For Unlimited Replayability In Video-Games

  • htugrulbuyukisik
  • 10 Mar 2024
  • 13 dakikada okunur

Algorithms are used in everywhere from smartphones to washing machines but they are only indirectly benefiting end-users because it is more useful when end-users are not fixing the bugs of these algorithms. Video games are mostly built on algorithms so they are more prone to exposing those difficulties to the end-users (players). Specifically, magic systems in RPG games require extra care to not create extra annoying bugs that force players to overcome them by decreasing quality of experience. Creating a spell system while avoiding potential bugs is not an easy task, so, this article is aimed at decreasing possible bugs, by offloading part of management to the players, by making it "customizable". One side-effect of this is the increased levels fun & replayability.



Balanced Spell System Without Direct Programming


Doing programming for building a spell (magic template) means fixing a lot of bugs before it becomes successful. RPG games do not accept errors. If it bugs in battle, it leads to "load game" part inevitably. To help this issue, any customization have to auto-solve all game-logic errors (not programming).


One example of game-logic error can be: unfair boosting of certain features. This issue is seen in a lot of popular RPG games. Some games gave total freedom to players to build god-like spells cheaply (or even for-free) in early stages, without any responsibility taken, sometimes also by DLC for base game.


How will players program their spells without losing fun? How will the game be fair and balanced?


Solving The Programmability Problem


When comparing two spells and their mana requirements, they need to be made of comparable or equal but smaller modules to be able to say that they are fairly balanced between each other.


Solution: divide and conquer


Just saying "summon skeleton costs 50 mana and fire-bolt costs 60 mana" is not enough to make it a fair decision. Fairness comes from being built on top of common rules. "summon = 50 mana" is not a rule.


Fire-bolt and summon skeleton both have teleportation in common. Fire-bolt teleports a piece of rock, then heats it and accelerates towards target. Summon skeleton teleports bones and gives them life and an alignment towards the mage. Or just teleports a living skeleton. Then the differing parts of these spells are the mass of teleported materials, positions of them and other phases.


So, magic can be divided into their smallest basic algorithm blocks, without being an exact programming language. But needs event chaining to be useful.


In summon spell, teleport event begins, teleport event ends, heat event begins, heat event ends, acceleration begins and ends. These separable parts can be computed independently, to be more fair in terms of comparing spells.


It becomes easier to compare just a teleport spell to a summon spell. Because summon also affects mind of summoned creature. It has more events.


Events can be divided into smaller events. Events can be run in parallel or in serial. Mages can get skills to process the events in parallel or serial, for efficiency or for power.


Players can easily draw their spells as "graph" structure, visually, with zero code written.




Solving The Unfair Advantage Problem


Using only multipliers and multiplying multiple sources for various parameters of spells can easily go off the charts if unchecked (a level 1 farmer discovers an exploit and starts bombing a city from sky with unlimited fly magic). But checking, on the other hand, leads to hard-coding which removes fun and is less maintainable as every new feature requires re-checking. Because they are one-way computations without any conservation of ... anything. To have a universe that does not explode in simulations, there has to be a conservation of energy and momentum. Universe has to obey some rules, except maybe in singularities.


Solution: conservation of energy


Generally, "mana" has been used as the potential to do anything related to casting a spell. If a player has more mana, then more spells can be cast. Some games have mana pools, some games have regenerating mana pools, some games have free-to-cast spells without any kind of consumption. Mana has been used in place of "energy" in games, specifically for mages (or just players who like magic in classless games). But it is not conserved.


In real world, energy is only converted to another type of energy, with less than 100% efficiency. Electrical potential energy can be converted to heat, with less than 100% efficiency. Heat can be converted to electricity, with less than 100% efficiency. There is always some percentage of energy not usable. Thanks to this, all kinds of energy sources, chemical, kinetic, light, ... can not be exploited to have free-energy. There is no free-lunch. They can only be converted and only with less-than-perfect efficiency. How to apply this to a game to make it "fair" in terms of replayability and balance? How to make a spell exactly balanced when compared to any other spell in game? By building a conversion table between actions.


Every movement, every action converts energy between types.


For example, summoning a creature is a popular action in RPG games, sometimes with a big player fan base in games due its attractivity for being simple and click-efficient way of solving problems. It feels safer to have warriours to tank against a boss. But, is it fair to consume 50 mana to summon a goblin while a fire-bolt costs 60 mana?


Summoning is the act of taking a creature from point A suddenly, then moving it to point B, suddenly. These two parts can be calculated like this:


Point A: work is done against potential energy between planet A (that contains point-A) and the creature. The work is equivalent to accelerating the creature to the escape veloicty for the planet surface. This is like 11 kilometers per second for earth. One needs to be thrown with 11 km/s velocity directly upwards, to be free of earth's gravity, eventually. This is thousands of times more energy than heating a stone and throwing it at 100 meters per second speed. Luckily, popping a mass at point B gives energy.


Point B: work is done by the potential energy between planet B (that contains point B), exactly same way as in point A.


So the energy different should be zero if creature is moved within same planet always. Maybe summoning a wolf in a planet that is the only source of wolves.


Point A: work is done by air pressure acting on the creature


Point B: work is done against air pressure because summoned creature can not exist in the same place with air. One has to go outwards. Preferably the air.


For points with same air pressure, this should be also same.


What causes the mana leak then? The imperfect conversion of energy. When creature is taken from planet-A, the given energy is not exactly same as the potential energy. Some of source energy is converted into heat too. Because there will be friction of air when air fills the volume left by the teleported creature. And it will be so wild that it can create an implosion on the surrounding environmental material. It lets the air around move at the thermal velocity, i.e. kilometers per second that is very fast.


The loss of efficiency, the extra required energy is compensated by mana. Even 99.9% efficiency can be ssen as very high energy because of escape-velocity being too high (11 km/s for Earth). 99.9% energy conversion efficiency is equivalent to accelerating the same creature to around 330 m/s or close to speed of sound which is still measurably high energy, perhaps comparable to heating a piece of stone by 1500 degrees Celcius and accelerating it to 30 meters per second. But it is now calculatable and backed by math rather than being fixed value like 50 mana vs 60 mana made up by mind.


The more mass of the creature, the more energy required to compensate for the loss during working for/against gravitational forces.


The more distance between points (of source and destination of summoning), the more energy compensation for the acceleration & deceleration of the thing that carries the converted mass. The creature's mass is converted to something, then its converted back to mass. But the part where it is moved from A to B takes some time. The more distance, the faster the thing needs to be at same intervals. Velocity is linearly increasing but kinetic energy depends on square of velocity (assuming that the converted thing is just another type of mass that is not visible and does not interact with other masses). So, the energy required depends on square of distance.


Energy required for teleporting a mass = Mass x C1 x (Distance ^ 2) where C1 is a constant of mana-to-energy conversion.


Mass (of creature) alone does not obey the magician. Some games also require it to be an ally of magician. This requires computing the energy required to compensate the difference of energies between state A and state B of the universe where in state A the creautre is not ally and in state B the creature is ally to the summoner. This is about Entropy. Entropy is about the number of possible microstates of the oberved system. When a glass of water is put in a corner of a room, after some time passed, the water molecules are found all around the room. Because in all microstates of the room, this one is the most possible state. Because it has the minimum total usable energy. Or, maximum entropy. Chaos increases, order decreases.


To compute the energy easier, simple question is asked. Does making this creature ally to the summoner mage make to world more chaotic or less chaotic?


More chaos = less order = less usable energy for the system = energy is taken out of system = mage gets mana


Less chaos = more order = more usable energy for the system = energy is given to system = mage consumes mana


How do we know if a summoned creature brings order to the observed destination system (game universe, around point-B)?


  • if creature kills any creature, ally or not, it increases number of microstates for the observed system. More chaos. Because now other creatures are free to do anything with the non-existence of the dead creatures. Zero creatures = maximum entropy or maximum chaos because now all atoms and molecules can go freely with their random motions and reactions within environments as they can never be grouped in shape of a sword, there can never be an arrow again. Mage gets mana.

  • if creature stops any creature from doing something, it makes all other creatures free to do more actions. But not as big impact as the death of the target creature.

  • if creature gives more freedom to any creature, it means less freedom to all other creatures, hence, more order for the system. This means mage consumes mana.

  • if creature causes the total population to grow, this makes even more order for the observed system. The mage consumes even more mana.

  • starting a war causes higher chaos so it generates mana

  • evading a war consumes mana


So, there has to be a parameter that tells how much a creature affects entropy of a system. It can relate to the skills of creature that change the number of creatures in the end.


  • If creature heals the boss and the boss kills more creatures, then the healer creature requires less mana to summon due to having more chaos in the end.

  • if creature heals the hero and the hero does not kill anyone, then the healer creature requires more mana.


Since the events are not known before they happen, this part of the mana consumption of summoning has to be "channeling" type, happening at the same time as the total population changes in the system.


Energy required for making a creature an ally = (change of population) x C2 where C2 is a constant for converting mana to energy.


The energy has to be computed for all timesteps (for real-time games) and turns (for turn-based games) that the creature is under effect of being charmed / hypnotized / bloodlusted / reanimated / controlled by the magician. Depending on the total population change because of creature, the caster needs to pay or gain mana, constantly until the effect is gone. What effect? Butterfly effect.


If a mage takes control of a skeleton and orders it to kill 1 soldier, it may cause chain reaction to make a group of soldiers losing a tactical advantage which causes a battle to be lost which causes a war to be lost after years.


So, a mage should not have the control of the summoned skeleton for free for eternity. Unless he has the mana pool required. Because the skeleton itself is count as +1 in the population and even if it does nothing, population is increased by 1 so the initial mana consumption is required and be given back to mage once the skeleton is unsummoned.


Summon creature initial mana requirement =  Mass x C1 x (Distance ^ 2) + (number of summoned creatures) x C2


Summon creature mana required per turn = (population growth of world per turn affected by summons) x C2


Unsummon creature mana required = - (number of unsummoned) x C2


So, a mage who causes total population of an island to increase needs to pay a lot of mana while it will be much less mana (after reducing the teleport cost) if it causes total destruction and the payment or gain will depend on the actions after the summoning.


Mages have to live with the consequences of their actions if they ever touch mana. Because energy has to be conserved. One day mage pays the price or gets a reward, in means of mana. But to keep things simple, the computation can be only done between summoning and unsummmoning instead.


All these are under the assumption of the summoned creature safely returns to its own original home, untouched, undelayed because any slight change in its environment would cause entropy change with unknown calculation requirement. Do they come from another world where mages unsummon them? Do they willingly enter a portal? Do they come and go instantly without losing any millisecond in their world? The observation window of the game should only include the point B. Because total entropy for both worlds tend to increase always.


Population growth calculation is only for the world that includes point B.


Calculations can be further simplified by these assumptions:


  • if summoner's side wins, world is conquered by that team and population grows freely to the maximum

    • mage always pays mana per turn

  • if summoner's side loses, world is conquered by enemy team and population grows freely to the max

    • mage always pays mana per turn

  • the summoned creature is only a catalyst for the reactions to reach the final state (population going max)


Summoning cost = C1 x Mass x (Distance^2) + C2 x (number of creatures)


Summoning upkeep = C3 x (number of creatures)


From the calculations above, it is not wrong to say that a mage should find it easier to summon stone golems when he is closer to the place where stone golems live. Some lore may say stone is converted to stone golem instead of being teleported. Then staying near a rock should make the summoning less mana-dependent. Similarly, water elementals could be cheaper to summon near a shore and wolves could be easier to summon near a forest, the parameter being encoded as a distance value.


If a summoned creature is higher level fighter, it can be count as a bigger number of summonings but with same total mass (considering just a level increase for same creature tpye).



Now, a spell system can easily compare a fire-bolt to a summoning - spell:


Fire bolt mana requirement = (C1 x Mass x Distance^2) + added heat energy + added kinetic energy


The first part is same, teleporting a stone piece from somewhere preferably close, then second part is about heating it to make it a "fire"-bolt, finally giving it high velocity to add to the damage.


Until this point, only energy conversion is discussed. Damage is yet another term to add to the inefficient energy conversions list. Some of energy is converted to damage in there. Damage means some molecular bonds broken. Because organisms can not live when some of their molecules are not in their place anymore. This is just chemical energy renamed.


Damage = chemical energy difference on the target


Mana change = (teleportation + heat + kinetic energy)


 (chemical energy difference on the target) = (heat + kinetic of projectile) x E1


So, when a fire-bolt hits a creature, the calculation is:


 Damage = E1 * (heat + kinetic)


Mana required = teleport + (Damage / E1)


Increasing the speed of fire-bolt increases mana requirement and damage, increasing temperature also increases damage and mana requirement. Increasing damage for same mass of fire-bolt always makes it more efficient because of the constant teleport energy. It can still work better if it teleports material from closer places.


One can reduce mass but increase speed to have less mana per damage. Or reduce mass but increase heat.


As long as all kinds of heating, teleporting, accelerating, breaking, fusing and entropy related energies are consistently computed, a spell system should be fair and balanced between all kinds of magic.


When a mage casts a force barrier spell to isolate half of population from the other, the upkeep of the barrier should be calculated not only with the energy contribution of attackers but also with the entropy of two isolated systems versus original unified one. Two isolated systems will always have less entropy than a unified one. So it requires massive mana upkeep, until barrier is gone.




Once energy - mana relation is conserved, the other thing to maintain "fairness" is to apply this to every action that a spell does. It is not enough to call fire-ball "aoe" and apply everyone same damage. It would be erroneous to freely apply the same damage to everyone under it, with same mana requirement.


Fireball has to do one of these:


  • keep mana requirement same, distribute (not copy) the damage (energy) to all affected targets

  • keep damage per target same, scale the mana requirement up accordingly with total energy applied


For the physical representation of fire-ball, it can be said that it starts as a dot from a center and grows with time. So if mana requirement is kept constant, then the total damage (energy) also needs to be kept constant and the biggest damage should go to the closest target. The weight of damage per target should be scaled accordingly with inverse square (or cube) of distance to explosion center. Because heat density decreases with the total area or volume of the growth and the area or volume depends on square or cube of distance to center.


For simplicity, it can be assumed to have constant density for all distances. Then it would be equal damage for all targets and only thing to consider would be to what to keep constant: damage per target or total mana requirement. Mana per target should always be constant for same damage per target.


For many games, more complex magic requires more mana just like that. It is a good guess, but without a consistent computational model, it does not stay fair nor balanced.


Fire ball is simple. Just something moves to a place and expands with fire. But some spells require much more thinking. For example, invisibility spell is not only physically hard to achieve but also depend on number of observers.


Invisibility type 1:

  • mage is teleported to another place: costs energy

  • visual data is sent from environment to mage but not the other way: costs energy

  • visual data position is moved on demand: costs mana

Invisibility type 2:

  • mage detects eyes of observers: costs mana

  • mage rotates eyes of observers so they don't see the mage: costs mana

Invisibility type 3:

  • mage detects thoughts of observers and deletes his image from them, every millisecond: costs mana



Invisibility in front of 2 enemies: 1x mana


Invisibility in front of 20 enemies: 10x mana if the invisibility is type 2 or 3


Invisibility in front of 20 enemies: 1x mana if the invisibility is type 1


All kinds of complex spells should be able to be modeled with same blocks of logic, algorithms, for fairness.




 
 
 

Comments


Why GPGPU? 
  • Offload image-resize to all GPUs and FPGAs so server feels more relaxed to host websites

  • Move compute-heavy sql table joins to C# side to let sql server handle the data-heavy parts.

  • Make particle physics programs performance-aware, even a mild overclock to one of GPUs will increase overall performance.

  • Write your own genuine kernel code to accomplish multi-GPU computing, easily without getting low-level on host side.

 UPCOMING VERSIONS: 

 

  • Device to device pipelining

 

  • Built-in image resizer functions.

 

  • Built-in matrix-multiplication functions.

 

 FOLLOW Cekirdekler: 
  • Twitter B&W
 RECENT POSTS: 
 SEARCH BY TAGS: 

© 2017 by Huseyin Tugrul BUYUKISIK. Proudly created with Wix.com

  • Twitter B&W
bottom of page