It is currently Mon Dec 11, 2017 5:13 pm

All times are UTC + 9:30 hours




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: "Lying" display code
PostPosted: Mon Jan 08, 2007 11:46 am 
Offline
User avatar

Joined: Thu Sep 21, 2006 6:48 am
Posts: 3681
Location: Location, Location
This is a D2D implementation of a fluctuating display code, more or less what I plan to use for Koshi:

First, give the CO three variables:

boolean display;
int slowdown = 0;
int variation;

The first determines if we are displaying or not
The second slows down the display
The third just determines the amount the damage fluctuates.

Easiest way to do this is just to have 200 defense when we're displaying, resulting in 0% damage for all units (though you'll need to account for terrain defense, or else you'll end up with negative damage displayed). You can just ignore the last two variables (slowdown and variation) if you do this.

[Note: 0 defense = 2x damage taken, which is why it's fine to have negative defense]

but that's lame and I refuse to tell you how to do that

Much better is a fluctuating display, which just flips all over the place.

Step 1:
Code:
    public void beforeAttack(Unit attacker, Unit defender, boolean attack)
    {
        display = false; //Time to do the real damage.
    }
   
    public void afterCounter(Unit attacker, Unit defender, int damage, boolean destroy, boolean attack)
    {
        display = true; //Time to make the display freak out!
    }

This just tells the code whether we're doing 'real' damage or not.

Then, in the getDefense() area, paste this:
Code:
    public int getDef(Unit attacker, Unit defender)
    {
            if(display)
            {
                if(slowdown == 10) //Every 10...uh...cycles? I dunno, the damage will change
                {
                    int baseDamage = BaseDMG.find(attacker.getAmmo(), attacker.getUType(), defender.getUType(),army.getBattle().getBattleOptions().isBalance());
                        if(defender instanceof Submarine && defender.dived)baseDamage = ((Submarine)defender).getDivedDamage(attacker.getUType());
                    else
                        if(defender instanceof Stealth && defender.dived)baseDamage = ((Stealth)defender).getHiddenDamage(attacker.getUType());
                    baseDamage = baseDamage * attacker.getDisplayHP()/10;
                   
                    if(baseDamage > 100)
                        variation = 20 + RNG.nextInt(50);
                    else if (baseDamage>=40 && baseDamage<=100)
                        variation = RNG.nextInt(30)-RNG.nextInt(100);
                    else if(baseDamage < 40 && baseDamage >10)
                        variation = 0-RNG.nextInt(400);
                    else if(baseDamage < 10)
                        variation = -500 -RNG.nextInt(200);
                    else
                        variation = 0;
                    slowdown = 0;
                }
                else
                    slowdown ++;
            }
            else
            {
                variation = 0; //RNG.nextInt(10)-RNG.nextInt(10);   
            }
            return (100 + variation); //error checking
    }


The if statement checking slowdown determines how quickly the damage changes - if you want it to be faster or slower, mess with that there.

The mess of if statements that checks baseDamage just tries to keep the display consistent. Originally the damage was a flat "as if Koshi had between 0 and 130 defense", but then I noticed that it was really obvious how much damage you 'should' do. So, the defense range tries to account for that.

_________________
"I got this [dragon tattoo] while a teenager. I met the greatest girl in the world and now I'm married. Problem is, she's afraid of dragons. I've started getting it removed. Will take years."


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC + 9:30 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Blue Moon by Trent © 2007
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group