Intro
If you’ve never heard of the H&H, here’s a snippet from their page:
Haven & Hearth is a MMORPG (Massive Multiplayer Online Roleplaying Game) set in a fictional world loosely inspired by Slavic and Germanic myth and legend. The game sets itself apart from other games in the genre in its aim to provide players with an interactive, affectable and mutable game world, which can be permanently and fundamentally changed and affected through actions undertaken by the players. Our fundamental goal with Haven & Hearth is to create a game in which player choices have permanent and/or lasting effects and, thus, providing said players with a meaningful and fun gaming experience.
But what’s special in my opinion is:
- it’s developed by a team of two Swedes
- it’s developed in Java using JOGL
- client’s code is open and the game itself is free, which means there are many alternative clients today.
You can find original sources’ license here:
http://www.havenandhearth.com/portal/doc-src
Following by the link to their official git repository and notes from developers.
However, the source I will be dealing with will come from the ‘Amber’ client:
https://github.com/romovs/amber
It provides some additional functionalities and is regularly updated:
Downloading and building from sources
>> git clone https://github.com/romovs/amber.git >> cd amber-1.68.0 >> ant
At this moment some weird errors may occure, but if so, just type ant once more and it should build it successfully. Now, to run, type:
>> cd build/ >> java -jar hafen.jar -U http://game.havenandhearth.com/hres/ game.havenandhearth.com
You’ll end up with a menu screen. However, (at least) to me it wasn’t over, because after logging in an error popped op:
I got to the file on the top of the stacktrace (Buff.java), found the line, had a guess what’s wrong and corrected the thing from this:
To this:
Then build the whole thing once again with ant and I finally managed to log in.
My brief modifications
Camera zoom
So I proceeded through the code for some time after that. I’ve been thinking what would be easy to do and came with an idea of simply enabling maximum camera zoom for a starter. It proved to be easy.
Cameras are managed in the MapView.java,
there’s a chfield function there, which I modified in the following way:
Btw, these comments are mine. I hardly ever stumbled on an existing comment, but if so, they’re mostly some rants/hacks over Java. Anyways, I rebuilt the project and got the camera scrolled up to the orbit with arrow buttons – it worked. I could see the whole area of the map around the player:
Detaching camera from the player
The following idea was:
- Space bar would toggle detaching
- If detached, one could move the camera to the point on the map, by simply click on some place at the map, but the player still wouldn’t move there
- Space bar pressed once again would attach camera to the player and focus on it
As I said, cameras are managed in the MapView.java.
There’s a function that returns object which defines the player:
And a function, that basing on that, returns player’s current coordinates:
…which I guessed, is used also by the camera, so I created an object that cached player’s position and updated it when:
- detached mode is on
- left click on map occurs
So getcc looks like this now:
I injected some of my code into the existing function that handles clicking, that is ‘hit’ function. Parts of it, before editing, looks like this:And after adding my code, it starts with:
To toggle detaching mode, I edited the ‘keydown’ function, which starts with:
I just added an additional branch to the if-else tree:
That’s all. I rebuilt it and recorded my modifications that you could watch it:
Summary
Next time we will tackle the networking code (which fun parts I already found, reside in the Session.java).