Saturday, March 31, 2007

Weapons are done!

I finished off the weapons. Well, most parts. There are a few minor things that I need to change. But most of the work is completed.

First of all: I changed how units keep track of their internal state. Initially, I had a unitState attribute in each unit class. Which worked reasonable, until I started adding attacking. I had to define several states, such as AttackGroundRotate, AttackGroundMove, AttackRotate, AttackMove, AttackGround and Attack. Yes, that's overkill...

What I did was implement the unit states as a stack. I then cut down the states to their basics: Move, Rotate, RotateTurret, Attack and AttackGround(There are a few more, but I'll safe you the hassle for those). When a unit is sitting idle, it's state contains just 1 state: Guarding. When moving the unit, it's a matter of pushing a bunch of states onto the stack and the unit manages after that. For moving, I just push Move and Rotate onto the stack. In the rotate state, it will determine the desired angle, rotate to it and pop the state. The next time the unit updates, it starts moving.

I also did the same with the gun, except I did make a different state for it, since some units have a seperate turret sprite. This will rotate the unit normally for units without a turret, and rotate the actual turret for those units who have one.

With the stack I also implement a CancelOrders function, which allows you to cancel whatever your unit is doing. However, it has a tiny bug(which I noticed after comitting my code, so I'll fix that after publishing this post): When moving, it stops the unit directly. The unit doesn't stop in the middle of a tile as it should.

The code for checking distance to the target, determining if the weapon is ready, etc. is very exciting to tell about. Only exciting thing I can think of is are the images below.

Only things left to do with weapons: Have the ornithopter fly attack patterns(Since it can't hover), have rockets leave smoke trails(Not in the original Dune 2 I believe) and have units spray smoke when their HP is below 50%.

As for now: Images!Medium Tank is being ordered to attack. Ornithopter is there for no reason

Medium Tank just fired it's weapon at the quad, which is doing nothing...

For those who are wondering why there isn't a healthbar showing in the first pic: I removed them, since I need to redo how healthbars work. The old way sucked donkey balls. Also, there is no image of the quad exploding, since I tried 4 times and still couldn't get to show the explosion.

1 comment:

Fundynamic - Stefan Hendriks said...

So you use states on a stack. But what if a tank wants to move, and at the same time move its gun to any unit nearby to attack?