Blast from the Past

My schedule has been swamped lately with one thing, couch-potatoing. I’ve been having a feverish cold that seemed to work its way to cause an inflammatory muscle around my shoulder so I haven’t been getting much done as of late.

However I started coding this evening for a while and had a blast from the past. I needed some way of calculating the way monster attributes should increase with levels. My first unworked and simplistic approach was something along this:

monster.HP = 50 + (level * 7);

Very crude and boring, every level an increase of 7? It would be too obvious and boring - so I thought up alternatives and leaned towards quadratic equations. Getting one to conform to something like a delta of 0.0 to 1.0 in both x and y seemed like a real hassle, my mathematics aren’t THAT up to date in my head. After a few minutes of trying to make these equations conform to the delta values I was interested in I scrapped it and went for an old solution which I in old Verge days called: TriMods.

Which is just the easy way out, emulating a quadratic function by splitting it up with triangles. I noticed my graphs I was interested were quite exact enough when split into five triangles and the approach is also quick to code and it’s easy to modify the level of precision by adding more triangles.

public static MonsterInfo Create(MonsterID id, int level)
   if (level < 1) level = 1; if (level > 99) level = 99;
   MonsterInfo info = new MonsterInfo();
   switch (id)
      case MonsterID.Chomper:
         info.Name = "Chomper";
         info.Attributes.HP = LevelInfo.ValueModifier(
                                    1, level,
                                    30, 630,
         info.Attributes.Strength = ...
         info.Texture = General.Textures["En_Chomper"];
   return info;

I’ve formatted the code a bit differently in this example - mainly the parameters for the ValueModifier method. Since we want a delta value from the method all the time, we fetch the value by saying startLevel 1 (one) up to endLevel level, the minimum value is 30 (what it starts at) and maximum value is 630 at maximum level (whatever it is: 99 or 255, etc), the CurveStrength determines which TriModSerie we use, one that grows fast in the beginning or slow.

Edit: Actually, I just realized the math will end up returning zero when we try to get the first level, because it would be the value of level 1 (minimumLevel) subtracted by the value of level 1 (currentLevel) which would result in zero. I’ll just either make minimumLevel 0 (zero) or I’ll make a simple method that fetches the value instead of a delta value inbetween two levels. Easy fix!

All attributes have different values depending on how this monster progresses over levels. Not that it matters a lot, but the values I use in this example aren’t the real ones, but thought I’d tell you.

A TriModSerie

A TriModSerie

A graphical explanation of why I’m using triangles, this lowresolution example shows a quadratic function made through triangles, hardly close to the same precision, but since we’re working with integers for HP, Strength and such, there’s not much use for 54.82 Strength and so forth.

public static class LevelInfo
   public static int MinimumLevel = 1;
   public static int MaximumLevel = 99;
   public static int ValueModifier(int oldLevel,
        int newLevel, int minValue, int maxValue,
        CurveStrength curve)
         Value(newLevel, minValue, maxValue, curve)
       - Value(oldLevel, minValue, maxValue, curve);
   private static int Value(int level, int minValue,
       int maxValue, CurveStrength curve)
      TriModSerie serie = TriModSerie.Static;
      switch (curve)
         case CurveStrength.Slower: serie = TriModSerie.Slower; break;
         case CurveStrength.Slow: serie = TriModSerie.Slow; break;
         case CurveStrength.Static: serie = TriModSerie.Static; break;
         case CurveStrength.Fast: serie = TriModSerie.Fast; break;
         case CurveStrength.Faster: serie = TriModSerie.Faster; break;
      float x = (float)(level / MaximumLevel);
      float y = serie.GetY(x);
      return minValue + (int)(y * (maxValue - minValue));

This is how it chooses TriModSerie and it’s pretty much in its first stage so things might change, who knows. I’m fairly sure it will look similar to this anyway.


This is where the actual value for the serie gets taken out, it will represent a percentage of how much Y should be after so much X (parameter value) and then we just return the correct value between the minimum and maximum.

That’s it for this update!

Share This!
  • Digg
  • Reddit
  • Facebook
  • Google
  • Technorati
  • TwitThis
  • Slashdot

Tags: ,

Leave a Reply

You must be logged in to post a comment.