Posts Tagged ‘structure’

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 :)

Programming in Austria

Sunday, June 15th, 2008

I’ve had this post as a Draft ever since I came back from Austria (which is a weird-ass country by the way), mainly due to the fact that I managed to change ssh port on my server without changing the firewall :)

So I finally connected a keyboard and screen and set everything up the way they was, which meant I could commit the changes I did to the Trekwar game to the server, and get them on this computer and grab some screen shots.

Friday
It is now possible to move your fleets around the map, Client allows you to press the tile the fleet should move to and then tells the server to move the ships.

Saturyday

Fixed a bug where the local copy of the move orders where not updated properly, implemented the starsystem controll window:
Trekwar System View

Sunday
Implemented build orders, now possible to build structures on planets. Queue not implemented yet.

Airplane
On the airplane back home I implemented the asteroid belts (high-altitude programming is fun).
Notice the beautiful asteroids drawn in mspaint on my laptop’s touch pad :)

Trekwar galaxy map with asteroid belts and fleet movements