Why I love Vandal Hearts

9 Mar

I’m a big fan of turn based strategy games and Vandal Hearts on the Playstation is one of the best I ever played. I recently found a copy and started playing through it from the beginning and it’s still as good as it ever was.

You control a group of fighters spread across a number of classic character classes (think warrior, healer, archer, mage). The objective on each map is usually to destroy all opponents (although it does throw some variety in such as destroy a collection of objects in a finite number of turns) whilst keeping your group leader, Ash Lambert, alive. There’s a basic rock / paper / scissors element to the combat with each class being strong against one type and weak against another. You can easily implement some strategic thinking; move your heavily armoured units down the middle and use them to absorb damage whilst flanking with your faster and ranged units. Mages can do an awful lot of damage but don’t have much armour so you need to keep them topped up with health. It’s simple but addictive gameplay and makes me wonder why the format doesn’t receive more attention. The most recent X-Com game was very similar and very good indeed.

The other thing I love about Vandal Hearts is the simple levelling up system. Once your party members get to level 10 and 20 they can upgrade their class. At level 10 most characters have a choice to make, so a healer can either become a bishop (super healer) or monk (healer / fighter). The best choice is for the archers because they can either become bowmen (super archers) or skyknights (fast moving aerial units). It’s clever and easy to follow.

There’s an interesting storyline (revolution, powerful ancient artifacts, Machiavellian politics) and most of the characters have a sub – plot devoted to them along the way. I think the character sprites are awesome, especially the way that Kira, one of the archers, looks when you level her up to Sniper class – she basically carries around a machine gun full of arrows.

Fantastic game. I remember that VH2 didn’t come close in terms of brilliance.

“Activation of the app XXX for the Windows.Launch contract was blocked with the error 0x80073CFC because its package is in state: Modified.”

27 Feb

Hit this error when I was trying to deploy the latest version of a Win 8 app to two tablets for a demo next week. The initial error message in the Event Log isn’t helpful, you have to drill down into Microsoft-Windows-TWinUI/Operational to get this specific message – and even then it’s not clear. I eventually found that renewing the developer license via the Show-WindowsDeveloperLicenseRegistration command in Powershell made the issue go away and the app would launch OK. It’s weird because I’m sure the Powershell installer (Add-AppxPackage) used to complain if the developer license was out of date but maybe this is being caused by something else.

BING API and GeoData

8 Jan

One of the requirements for the Windows 8 app that I am working on is for the user to be able to click on a point on a map and create a service request. The service request form should have some details auto populated, such as the address that the user is currently stood at or nearby to.

This is more complicated than it sounds. The BING API doesn’t have an address layer by default, so I have to use the spatial data for addresses stored on the corporate network. The grid references for this spatial data is stored as “OSGB 1936″, or Eastings and Northings; basically a 6 digit figure that the OS uses for X and Y coordinates of properties. I also need to work out which addresses are closest to the point on the map that was clicked on so that I can present some options to the user – I think it would be wrong to say ‘you are definitely at address x’.

I have found a few excellent resources on the web that have helped me figure all this out. The first is published by Movable Type Ltd where the guy who (I presume) owns the site, Chris Veness, has published two excellent articles about finding the distance between two lat / long points, and converting east / north to lat / long, and vice versa. There are also some complete javascript libraries freely available. He explains all the maths involved in the calculations and it’s a pretty amazing piece of work.

I decided in the end to just send the lat / long that the BING API generates on a map click back to a RESTful web service to find which addresses are closest; I didn’t fancy downloading the entire gazetteer and doing all the calculations client side. The maths to work out the distance is done using the Haversine Formula and Seth Long has a C# version on his blog; I have used this in my web service.

So the eastings and northings in my spatial database are no good for working out lat / long distances; I had to find a tool that would convert all east / north to lat / long. Fortunately the Ordnance Survey publish a tool called Grid InQuest that you can feed a text file of co-ordinates in and get a list of converted co-ordinates back. It’s really simple to use and I managed to convert 77,000 + records in seconds. It’s also the most accurate – beware of conversion functions that you find on discussion or code sites because they might be a few metres out. There is a dll file that comes with the Grid InQuest software and you can import it into a .NET application but I couldn’t get it to work – if anyone reads this and has managed to do so please post a comment and let me know what you did.

Windows 8 App – Polling a web service every x seconds

19 Dec

This morning I did a little bit of work on polling a web service at a pre – defined interval. One of the requirements of the project I am working on is for the application to pull down a fresh set of data every thirty minutes and show new and updated information to the user.

The actual polling function uses jQuery and a technique known as ‘long polling’ which is more effective than the traditional setInterval technique, especially with asynchronous requests. You can read more about it here. I found a working example of the function on StackOverflow so won’t take any credit for reinventing the wheel.

Here’s my version of the code:

function poll() {
url: 'http://server/application/handlers/generaterandomnumber.ashx',
method: 'GET',
dataType: 'text',
cache: false,
success: function (data) {
setTimeout(function () { poll() }, 10000);
app.sessionState.randomnumber = data;
error: function (data) {
setTimeout(function () { poll() }, 10000)

To generate some sample data I have written a simple generic handler in C# that produces a random number between 1 and 10 every time it is called. It’s important to turn caching off on your AJAX call otherwise you get the same number every time! You can also see that the value returned from the web service is added to the application session so that I can grab it on any page.

The function goes in default.js in the Windows 8 app. On a single page navigation app with multiple separate page controls you want the function to keep pinging away regardless of which page the user is currently using. So poll() goes into your initialization function like so:

if (args.detail.previousExecutionState !== activation.ApplicationExecutionState.terminated) {
                // TODO: This application has been newly launched. Initialize
                // your application here.

Last bit is to print the number to screen. I have a page called sync.html and I print the current date, and whatever is stored in the session, to a div on that page. The timer won’t automatically update this value on sync.html – I would have to write another local poll function to do that.

ready: function (element, options) {
            // TODO: Initialize the page here.
            var x = WinJS.Application.sessionState.randomnumber;
            var currentTime = new Date();
            document.getElementById("random").innerHTML = currentTime.getTime() + ' | ' + x;

Windows 8 Store App and the BING Map API

18 Dec

Pretty near the close of play yesterday I discovered that the GIS solution my organisation uses won’t integrate with the Windows 8 Store app that I am developing (WinJS IFRAME Permission Denied). My boss and I agreed that looking at a mapping API such as the one that BING provides was worth doing in the context of the project because it will come up sooner rather than later and I would much rather be prepared.

So I spent quite a frustrating few hours this morning trying to get the API to integrate with a Windows Store App. Actually getting a map to render was quite easy – this post on the BING maps blog told me everything I needed to know. But moving on from that and getting basic functionality such as zooming the map in / out on a button click was irritating.

I read somewhere that the API is the same as the Javascript AJAX API described on this site but the suggestion of map.ZoomIn() to get the map to zoom, for example, didn’t work.

There are a few code samples scattered across the web for C# / XAML, a few for Javascript but there doesn’t seem to be a single central source for developing maps in Javascript / HTML 5 for Windows Store. Bit disappointed at the lack of support at the moment, and surprised too because a lot of what mobile devices can offer is location – based data and services.

Anyway, here’s what I have managed to figure out so far:

1. The samples will tell you to create a div to act as a container for the map on the screen. By default the map takes over the entire screen, so if you want to make it a certain size the css is:

<div id="myMap" style="position: relative; width: 100%; height: 100%;"></div>

Here’s the HTML for a Page that I have added to the solution called map.html. I’ve created a grid structure with the map on the left of the page and a couple of spans and a couple of buttons on the left for zoom in / out and displaying lat / long of current position.

<!DOCTYPE html>
    <meta charset="utf-8" />

    <!-- WinJS references -->
    <link href="//Microsoft.WinJS.1.0/css/ui-dark.css" rel="stylesheet" />
    <script src="//Microsoft.WinJS.1.0/js/base.js"></script>
    <script src="//Microsoft.WinJS.1.0/js/ui.js"></script>

    <link href="map.css" rel="stylesheet" />
    <script src="map.js"></script>

    <!-- load jquery -->
    <script src="/js/libraries/jquery-1.8.2.min.js"></script>

    <script type="text/javascript" src="ms-appx:///Bing.Maps.JavaScript//js/veapicore.js"></script>
    <script type="text/javascript" src="ms-appx:///Bing.Maps.JavaScript//js/veapiModules.js"></script>
    <div class="map fragment">
        <header aria-label="Header content" role="banner">
            <button class="win-backbutton" aria-label="Back" disabled type="button"></button>
            <h1 class="titlearea win-type-ellipsis">
                <span class="pagetitle">Title</span>
        <section aria-label="Main content" role="main">
            <div id="content" style="display: -ms-grid; -ms-grid-rows: 1fr 1fr; -ms-grid-columns: 60% 60%; height: 100%; overflow: scroll;">
                <div id="leftContainer" style="-ms-grid-column: 1; -ms-grid-row: 1; -ms-grid-row-span: 2;">
                    <div id="myMap" style="position: relative; width: 100%; height: 100%; "></div>
                <div id="rightContainer" style="-ms-grid-column: 2; -ms-grid-row: 1;">
                    <span id="lat">LAT</span>
                    <br />
                    <span id="long">LONG</span>
                    <br />
                    <button id="zoomin">Zoom In</button>
                    <br />
                    <button id="zoomout">Zoom Out</button>

Here’s the javascript ‘code behind’. It loads the map (you will need to generate your own API key, see the BING blog link above) and set your own starting lat / long. There are handlers for the zoom in / out buttons and there’s also code that I have taken straight from the Microsoft site to use Geolocation – don’t forget to enable it in your appmanifest. You’ll also need to run the solution through the simulator on VS2012 and click the ‘Get Location’ button in the tool bar on the right hand side of the simulator. Notice how the zoom in / out use map.setView to set the zoom level.

// For an introduction to the Page Control template, see the following documentation:
// http://go.microsoft.com/fwlink/?LinkId=232511
(function () {
    "use strict";

    var map = null;
    var loc = null;

    function initMap() {
        try {
            var mapOptions = {
                credentials: "api-key-here",
                center: new Microsoft.Maps.Location(lat, long),
                mapTypeId: Microsoft.Maps.MapTypeId.road,
                zoom: 15
            var mapDiv = document.querySelector('#myMap');
            map = new Microsoft.Maps.Map(mapDiv, mapOptions);
        catch (e) {
            var md = new Windows.UI.Popups.MessageDialog(e.message);

    function getLoc() {
        if (loc == null) {
            loc = new Windows.Devices.Geolocation.Geolocator();
        if (loc != null) {
            loc.getGeopositionAsync().then(getPositionHandler, errorHandler);

    function getPositionHandler(pos) {
        document.getElementById("lat").innerHTML = pos.coordinate.latitude;
        document.getElementById("long").innerHTML = pos.coordinate.longitude;

    function errorHandler(e) {
        //var md = new Windows.UI.Popups.MessageDialog(e.message);
        var md = new Windows.UI.Popups.MessageDialog(getStatusString(loc.locStatus));

    function getStatusString(locStatus) {
        switch (locStatus) {
            case Windows.Devices.Geolocation.PositionStatus.ready:
                return "Location is available";

    WinJS.UI.Pages.define("/pages/map/map.html", {
        // This function is called whenever a user navigates to this page. It
        // populates the page elements with the app's data.
        ready: function (element, options) {

            Microsoft.Maps.loadModule('Microsoft.Maps.Map', { callback: initMap });

            var hello = document.getElementById("zoomin");
            hello.addEventListener("click", this.zIn, false);

            var goodbye = document.getElementById("zoomout");
            goodbye.addEventListener("click", this.zOut, false);

        zIn: function () {
            var zoom = map.getZoom();
            zoom = zoom + 1;
            map.setView({ zoom: zoom });

        zOut: function () {
            var zoom = map.getZoom();
            zoom = zoom - 1;
            map.setView({ zoom: zoom });

        unload: function () {
            // TODO: Respond to navigations away from this page.

        updateLayout: function (element, viewState, lastViewState) {
            /// <param name="element" domElement="true" />

            // TODO: Respond to changes in viewState.

I hope these samples help anyone who wants to integrate a map into a page – all the code samples I have seen so far presume that the map is going on default.html which won’t be for everyone, and the javascript on the page is subtly different.

0x2efd in Windows 8 app using Web API

12 Dec

Started working on the communication between Windows 8 app and Web API web service to send / receive data from app to servers. Wrote a simple web service following this guide (Mike Wasson has written the best documentation I have ever seen from Microsoft about one of their development tools, I salute you), deployed to server and tested. Returned JSON so no problems there.

Added the $.getJSON command to the javascript in my Win8 app and set it to write its output into a div. But nothing happened. Finally spotted an XMLHttpRequest error in the JavaScript Console in VS2012 – see the picture below:





At first I thought this was a cross domain issue so I went through the steps that we follow internally to get cross domain stuff to work – namely adding it to the trusted sites in the local intranet zone and adding a proxy exception. But this didn’t solve it. Fortunately I stumbled across Gyorgy Balassy’s post that told me I had to edit the package.appxmanifest file and enable Private Networks (Client & Server) (it’s in the Capabilites section in the current release). Ticked the box, re-ran the app and the json from the web api was pulled down and presented. Fantastic.

Offline data storage with a Windows 8 application

12 Dec

Yesterday I started looking at the nuts and bolts of developing a Windows 8 app. If anyone is trying to do the same and finding the information on the web conflicting then I can highly recommend the following text books:

  1. http://www.amazon.co.uk/Metro-Revealed-Building-Windows-JavaScript/dp/1430244887/ref=sr_1_1?ie=UTF8&qid=1355307449&sr=8-1 (gets you straight into the essentials)
  2. http://www.amazon.co.uk/Programming-Windows%C2%AE-Apps-HTML-JavaScript/dp/073567261X/ref=sr_1_1?s=books&ie=UTF8&qid=1355307483&sr=1-1 (loads more detail)

One of the requirements for the project I’m working on is to have offline storage in case an internet connection isn’t available. The area that I work in does have some 3G blackspots and sometimes the people going out with devices will be going into buildings where the signal just doesn’t get through.

I did start thinking about using either SQL Server 2005 Express or SQLLite to accomplish this but was put off for a couple of reasons. SQL Server Express seems like quite a big overhead and when I tried to deploy a test application to a tablet with the SQLLite / C++ Runtime libraries referenced I got a security error message from Powershell. This set my spidey sense tingling and I started looking at document databases (or NOSQL databases) instead. I had already written a test MVC3 app using RavenDB but wasn’t happy with the javascript documentation. A web search yesterday turned up the Apache Foundation’s CouchDB which has a much better documented jQuery / Javascript API.

Setup was a doddle – download the CouchDB Windows installer from the CouchDB site and run it on my Win8 VM that I’m using for development. Test that the database is up at http://localhost:5984/_utils. I also found some information about something called CouchApp which is a command line tool that supports CouchDB so I downloaded that and installed it too.

Actually getting the Windows 8 application to talk to CouchDB was a bit irritating to start with and I drew inspiration from Bradley Holt:


  1. http://bradley-holt.com/2011/07/couchdb-jquery-plugin-reference


The main thing to watch out for is that in Windows 8 you need to reference the scripts that Bradley suggests in your application – you can’t put external http:// references to them. So you will need to download the jQuery library and stick it in your \js folder in your VS2012 solution. You will also need to search your computer for jquery.couch.js – it’s on there somewhere. Again, put a copy in your \js folder and make sure both files are referenced in default.html (load the jquery library first).

One of the things that Adam Freeman suggests is that you add three additional functions to your default.js file – performInitialSetup(), performRestore() and performSuspend(). I guess these are to do with the application lifecycle (I haven’t got that far yet) and performInitialSetup() is called in the main body of default.js (app.onactivated). I put a small amount of jQuery into the performInitialSetup() function – set the urlPrefix for couch ($.couch.urlPrefix = “http://…&#8221;) and made the $.couch.info ajax call to get some info from the database. This eventually worked fine and I was able to print the version number of the couchdb instance to a div on the Win8 app page.

Next step is to try and read some documents from the database and print them into some sort of list on screen. But that fact I have managed to get the version number out means I’m hopefully not too far away.

Edited 12/12/12 at 12:55

After I bit more work I was able to communicate with CouchDB and pull some data out of the database. I followed the Getting Started guide on the Couch site here so set up some data in the database and a view of that data (the view is pretty important and I need to learn a lot more about how these work). I then used Bradley Holt’s site to write an ajax call against the view, and parsed through the json output then printed it all to a div.

Next job is to write some code that will communicate with a web service async to pull a list of information down from our servers and load it into Couch so that it can be presented to the user. I also need to get my head around the Model – View element of the app design and getting the repository – esque functions demonstrated by Adam Freeman in Metro Revealed… to map to Couch.


Get every new post delivered to your Inbox.