Development > Newbie Coding
New Auto Mission code proposal
Destructavator:
OK, I've talked with BTAxis and looked over the old proposed Auto Mission code on the wiki page. The old proposal doesn't factor in a lot of stuff, doesn't have some realism factors (Two wounded units can be more deadly than one healthy one), and it also has the issue of the Balance Of Power slamming into a "solid wall" if it strays above 1.f, rather than curving towards it.
This pseudo code I'm going to list here would fix much of that, and after something like this is put in the could could then pick back up on the old proposal starting from "Injuries and Casualties" once the Balance Of Power is calculated. This new system would let that balance curve in a controlled amount (anywhere from a slight adjustment to leaning heavily) towards the range boundaries of 0.f and 1.f without completely reaching them. This means a lone soldier could still have a very slight chance of winning a mission against a group of aliens (although that slim chance wouldn't be pretty for the soldier.
I'm also attaching two pics showing examples of how the curve function can work with different values. The result isn't quite "exponential" but is very controllable.
--- Code: ---// Custom functions for manipulating floating point number
// up and down without straying outside of 0.f and 1.f,
// also doesn't need min() or max(), but rather keeps
// everything in a nice curve.
// "pushV" and "pullV" are floating point parameters
// that set how rounded the curve is, or in other words
// how much to push or pull toward 1.f or 0.f.
// "pushV" and "pullV" can range from 0.f (very subtle)
// to just under 1.f (extreme change). I personally
// would not recommend going above 0.99f (usually).
float PushUpward(float oldValue, float pushV)
{
float newValue = (((1.f-pushV)+1.f)*oldValue) / ((1.f-pushV)+(1.f*oldValue));
return newValue;
}
float PullDownward(float oldValue, float pullV)
{
oldValue = (1.f - oldValue);
float newValue = (((1.f-pullV)+1.f)*oldValue) / ((1.f-pullV)+(1.f*oldValue));
newValue = (1.f - newValue);
return newValue;
}
// Now for the actual Auto Mission code
float BoPindex = 0.5f; // Starting or "base" balance of power (chance of sucess)
// for the mission, can be set lower for hard game
// difficulty, or higher for an easier game. NOTE: If
// this is set higher or lower it should NOT be set to a
// perfect 0.f or 1.f, it should always be somewhere
// in-between. Normal games start at 50% success rate,
// before we of course "play" with it.
float numberOfSoldiers; // Total number of soldiers on a mission, and yes, it
// needs to be casted into a float, you'll see why shortly.
float numberOfAliens; // Same thing for aliens.
float numberOfCivs; // Same thing for civilians.
float playerFactor = 1.f;
float alienFactor = 1.f;
float civFactor = 1.f;
for(x=0; x < numberOfSoldiers; x++)
{
float tmpF;
tmpF = soldier[x].currentHealth / soldier[x].maxHealth;
tmpF = PushUpward(tmpF, 0.5f); //This accounts for the fact that two wounded
playerFactor += tmpF; //Soldiers can be more effective than one healthy one.
}
for(x=0; x < numberOfAliens; x++)
{
float tmpF;
tmpF = alien[x].currentHealth / alien[x].maxHealth;
tmpF = PushUpward(tmpF, 0.5f);
alienFactor += tmpF;
}
for(x=0; x < numberOfCivilians; x++)
{
float tmpF;
tmpF = civ[x].currentHealth / civ[x].maxHealth;
tmpF = PushUpward(tmpF, 0.5f);
civFactor += tmpF;
}
float playerFactor = float (1.f / playerFactor);
float alienFactor = float (1.f / alienFactor);
float civFactor = float (1.f / civFactor);
if( Civilians are infected and hostile ) alienFactor = PullDownward(alienFactor, civFactor*0.5f);
if ( playerFactor > alienFactor )
{
float tmpF = playerFactor - alienFactor;
BoPindex = PullDownward(BoPindex, tmpF);
}
if ( playerFactor < alienFactor )
{
float tmpF = alienFactor - playerFactor;
BoPindex = PushUpward(BoPindex, tmpF);
}
// Here the sums of equipment scores are factored in.
float plyrWeaponFac = float (1.f / soldierEquipmentScore);
float alnWeaponFac = float (1.f / alienEquipmentScore);
if ( plyrWeaponFac > alnWeaponFac )
{
float tmpF = plyrWeaponFac - alnWeaponFac;
BoPindex = PullDownward(BoPindex, tmpf);
}
if ( plyrWeaponFac < alnWeaponFac )
{
float tmpF = alnWeaponFac - plyrWeaponFac;
BoPindex = PushUpward(BoPindex, tmpf);
}
--- End code ---
Note: All the "0.5f" values within the custom push/pull functions are "magic" numbers that could be changed to alter game mechanics.
Mattn:
can you please post this on the patch tracker with a link to this thread?
Destructavator:
--- Quote from: Mattn on March 30, 2011, 10:41:41 am ---can you please post this on the patch tracker with a link to this thread?
--- End quote ---
OK, Done.
Destructavator:
OK, I thought I'd start by creating a header with the custom "helper" functions. I put in it several algorithms, including some I might use for additional coding down the road.
It is currently written to go in the "common" folder, right next to "mathlib.h" If this is an OK spot for adding custom functions like this, should I go ahead and commit this via Git?
(At some point I'll put the mentioned graphic together.)
Edit: Oops! I meant "shared" for the folder name. Sorry, I was working on more than one new source file in different places. (I'm still trying to figure out the best place to put new source files.)
Mattn:
I'll check it asap. But i currently do not have inet at home
Navigation
[0] Message Index
[#] Next page
Go to full version