Posts Tagged ‘faction’

Oups

Monday, March 15th, 2010

While cleaning up in the core classes of Trekwar yesterday (documenting functions, formatting/structuring code, minor improvements) I also saw lots of equals(Object o) methods. And in my infinite wisdom I decided to use generics since it is used pretty extensively throughout the code anyway, so I changed basically all the equals methods.

example:

public boolean equals(Object o) {
        if(o instanceof Structure)
            return equals((Structure)o);
        return false;
    }

was changed to:

public boolean equals(Structure s2) {
        return name.equals(s2.getName());
    }

Now this is not a problem when writing code, as you pretty much always compare objects of the same type. However, the code also uses the Java Collections contains() method a few places, and it always uses the equals(Object) version. So when my classes no longer provided this method, the default one inherited from java.lang.Object was used instead. This caused a strange array of bugs to appear (star systems on the map not shown with faction color/icon except for the Cardassians for some strange reason, users not having any technologies, unable to build any structures, generally erratic behavior, etc..). Luckily I discovered the cause pretty quickly and only wasted about an hour or so on this :)

I guess the lesson is that objects that needs to be compared, directly or indirectly by contains() or other methods, should always define an equals(Object) method that just passes the call along to the equals method written with generics.

public boolean equals(Object o) {
        if(o instanceof Structure) {
            return equals((Structure)o);
        }
        return false;
    }

And perhaps that you should not mess around with your code for hours on end without stopping to test if you broke it once in a while :)

JavaEaster

Friday, April 10th, 2009

Easter is almost over, and I used most of the time to complete the Trekwar shipdesigner, and set up lots of hulls for it.. I also created a chat system for the game.

ShipDesigner:
trekwar_shipdesigner_boomship

Faction Hulls:
xtrekwar_hulls_easter09

Chat:
trekwar_chat

I was planning to implement the ship actions, like colonization and ship combat this easter. But I think I’ll work on the Starsystem management system instead, as I redesigned it heavily this easter.

Trekwar shipdesigner

Monday, October 13th, 2008

I recently had a good idea for my Star Trek game, this would also solve the problem with some factions having very few ships designs, and might even allow me to add more factions (Ferengi, Dominion, Kazon, borg?), seeing that finding and balancing enough ship classes for each faction was the biggest problem with adding more factions.

It might even make it possible to add some more exotic factions (Xindi, Gorn, Breen, Son’a, Tholian, Vidiian, Hirogen, Tzenkethi or maybe even the Terran Empire :)

Instead of just having 4-5 static ship classes where all ships made of this class are identical, one could have a little star ship designer where you fit a hull with the components you want (warp drive, impulse drive, phasers, torpedo launchers, sensors, fusion reactors, shield emitters, armor, cloaking devices, troop transports, colonization and terraforming tools).

This means I will have to do some re-designing the next time I have time to work on the game (wont be that much, only implemented 2 ship classes so far) :)

According to my superior mspaint skills, the interface will look like this: