Part 27 Choosing Ships and building squads.

Graftgold Memories

I had an interview yesterday for an article in Retrogamer about Graftgold. It is always fun talking about the old times. Andrew Braybrook came along too so we had an afternoon of reminiscing.  Some readers might be interested in forming a company to develop games. My first job was working for HM Customs and Excise so I learnt a lot about companies and trading as a sole trader and partner ships.  Some of the tax rates and rules may have changed over the years but its basically the same set up nowadays. When I started off I traded as a sole trader with a trading name of ST Software. It is the easiest way to start a business as you do not register a company and submit annual returns. You should still keep a proper account as you need to fill in a tax form at the end of the tax year and declare your profit. I would recommend that people have a chat with a local accountant. I had an accountant recommended to me  He earned his pay by  showing me all the things I should put in the accounts as expenses. I worked from home so he advised I apportion household bills such as electricity and gas. He saved me much more tax than it cost to pay him.

  The basic differences between the  ways of trading are as follows:

Sole Trader.
You can trade as a different name as long as it is not misleading or violating any trademarks. You do not have to register it but it make sense to protect a name you want to build up. You should use the trading name on documents such as invoices but put your own name as well. A sole proprietor is responsible for all there debts in full. This can be an advantage when beginning because people you trade with know you cannot just cannot close the company and walk away from the debt.  The company and you are the same legal entity.    Tax rules change over the years but when you get going you usually have to pay some estimated tax in advance and then the balance when the trading year is over.   The other thing you have to sort out is National Insurance and nowadays pension contributions. I had to pay an amount every month for me then a balance when the account was drawn up. You have to make sure you keep enough money in the bank to pay the NI and Tax payment when it is due or there are severe penalties. So it is important not to spend all your profit.
If you employ someone then you have to pay their tax and NI as you go along. You fill in a page of their P45 and send it to the local tax office when they start and have to issue a p45 when they leave. You have to fill in end of year forms etc. I found it quite easy but fiddly. In the end I taught my wife to do the payroll.  A letter to your local tax office to inform them you want to employ someone will get you an employer number, to look up the amounts and a starter pack of all the forms you need.
I started off a separate bank account to keep the business money and mine separate. It made accounting easier. I used to keep up the accounts and just give them to the accountant at the end of the business year for a tick check and perform final adjustments.  This kept his costs down to a minimum. There are on line account systems that can be used nowadays. It is best to use a system that the accountant can deal with. I started off doing it all by hand then wrote an accounting system on the Spectrum when I needed to become VAT registered.  This happens when your expected turnover goes over a threshold limit. Then you must register and add VAT onto all your invoices. When I worked for HM I saw many traders whose had omitted to register and in those days they would just consider the invoice was inclusive of tax and demand the payment of the VAT even though it had not been collected from the buyer. There are strict rules and penalties with VAT you have to submit returns and pay on time. You need to become fully aquainted with VAT before you start trading.  I had a VAT inspection visit in my first year of VAT trading and they were pleased how I kept the accounts up to date. However the best reason to do accounts is so you can see how you are doing and how much you have to spend

This is like a Sole Trader except that two or more people are trading together. The important thing to remember is that each individual in the partner ship is responsible for the total debt. People often think they just have to pay their share but that is not right.  It is a legal principle called "joint and several". I advise any thinking of starting a partnership to chat to a solicitor and an accountant. They should get a solicitor to draw up a legal document to form the partnership.  I chose not to form a partnership, instead I employed Andrew. That way the responsibility and risk was all mine.

Limited Company
A limited company is a legal entity in its own right.  You need to be familiar with company laws covering the running and accounting. The companies liability to debtors is limited to its own assets. So if it goes bust in theory the directors can walk away and not be pursued by the debt, as long as they followed the rules. That means that no one will lend a limited company money or give large credit without some form of surety. So often directors have to sign to say they will personally accept responsibility for a debt. When I went to rent my first office the landlord refused to deal with Graftgold Ltd and wanted me to sign in my own name.

I changed my trading style to a limited company because the tax is treated differently. All profit a Sole Trader makes in a year is taxed and if you make a big profit you start paying higher rates of tax.
The thing with royalties is you get the money in a short period and then nothing while you write the next game.  This means one year you may pay loads of tax at a higher rate and the next year not use your whole tax allowance. There are some things you can do with an accountants help to even it out but I found it better to trade as a limited company.  A limited company pays tax on profits at a different rate which can be a smaller percentage, especially if it is a smaller company and you are make enough profit to put you in a higher tax rate.  I became become an employee of the company and paid tax and NI as I was paid monthly. The rules for NI were slightly different as I was a director: for example there was no ceiling to NI if I wanted to pay myself a bonus I had to pay a set percentage NI.  I used to take a steady amount each month. Then it was easier to work out how much money the company needed.  The bank balance would build up in the good years and  this money paid us in the years where royalties were not so big. An accountant will advise  when it is best to have a limited company, it changes depending on the current tax rates and rules. When the company got bigger I felt more at ease with a limited liability.  If you resist putting you house up to borrow money all you have to lose is the company. That is better than losing your personal wealth such as your house and savings.

To form a limited company I just asked my accountant who found a preformed company that suited my business.  People go through all the hassle of registering a company and it sits dormant until someone buys it for a small fee. It is the quickest way to form a Ltd company. You have to make sure the company has never traded and its description of its scope of business includes what you are doing.  We were told we could change the name if we came up with one in a few days but rather liked the off the shelf name "Graftgold" so decided to keep it.

Other things to consider are employment rules such as paying pension contributions and working conditions, Legislation changes all the time and you need to keep up to date.

Deepest Blue

It seems ages since the last blog. I still haven't finished testing the building of bases but it is coded. The problem I had was to get the game to the state when bases can be built. A pioneer ship has to find a warp to a new sector, travel down it and find a "lagrange point" where a base can be built. When tried this out I found various issues. I decided to get the process of switching ships to and from AI working first.  I already needed an autopilot to take over when the player is busy looking at a computer display. While I thought about this I decided to change the initial computer display where you can select different screens to take place as part of the HUD display so you can see the game in the background. This meant a rearrangement of the screen building XML and I was pleased my system could handle this without any changes. The system of keeping the data specification of the forms away from the code has really been paying off. I can rapidly change things in the XML and have minimum code changes to add new fields or move things about.


This basically forms a window the size of the top of the screen. Within this it creates a
 sub window that I can switch on or off. This has its own 3d scene and camera and a carousel control which contains a set of thumbnails of other screens. The second scene is the actual game scene and camera the pad defines a control pad that operates within the scope of the window.
The screen choice carousel displaying in game. 

Ship Choice Screen.
As the player can have many ships I needed a screen so the player can choose which one to fly. The screen needed to show the details of each ship and what it was doing. The player can group ships in a squad so I thought this screen would be a good place to administer this. So the actions needed were, exit, show ship ,show squad, form squad, disband squad, add ship to squad, leave squad, change the AI level of a ship. I also added buttons to change the squad formation and scale and to buy, sell and update the current ship.

I knocked up a static prototype quickly by cutting and pasting from other screens. I wanted to show a picture of the  ship  and the formation of  the chosen squad.  Putting squad details and ship details on the same screen game me a bit of a logical problem. I wanted the squad details to list each ship in the squad. To add a ship you page through you ships and the press the JOIN button. So paging a ship in another squad must not change the chosen squad display.  I also wanted ships to be able to join other players squads. I decided not to show squads that were not owned by the player. It just has a LEAVE button so you can take the ship out of the squad.  
The ship choice and squad screen.

So much coding and testing and the new screen was  up and running. It was ages ago that I wrote the underlying Squad routines and found a few little things to adjust. Then I created my first squad and went to the game screen. When I flew the lead ship the others turned but refused to move. Something I had done over the last year had broken the squad ship movement. I traced the routine and the move was set up ok but only every 5 cycles.  It took two cycles to change the throttle and then use this to power the engines then this to do the acceleration. I bit of code rearrangement was needed so it worked in one cycles processing.

My squad formation code needs a bit of tweaking. At the moment each squad ship has a set place to get to depending on the position and direction of the squad leader. I have a better system whereby a ships position is determined by vector from the nearest ship ahead of it, rather like birds fly. This gives a more natural formation that looks as though people are flying the ships and can also work if the squad breaks and reforms.  each ship is automatically promoted to its immediate leaders position if they are destroyed. We did this in Realms to preserve coherent formations as men were killed in the battle screen.

I tried running a mission to explore a warp and explore the new sector.  When I exited the warp path the ships computer told me it did not know the way to the target sector. I should have been there so something had gone horribly wrong. It abandoned the mission automatically but then could not tell me the way home. Silly computer it should be the warp exit I just came out of.

I generate connecting space sectors automatically. each link should work both ways and be marked as a known path when it has been travelled down. So it was back to the drawing board. As the data was spread over several locations I decided to put this one to bed by writing a test routine to list out all the warp connections and the calculated routes between them. I record how many steps between each combination of sectors and the sector to travel to as the first step. I just call the next step routine  each time a warp is traversed until I arrive at the correct sector. The data has to tell the nav computer the location of the next warp point within a sector so it can be displayed on the HUD. Each faction in the game has its own data about the routes which is expanded when it finds new paths.  So he listing had to show the complete picture about how warps connect sectors then each factions view of this.

That is all done I just now need to rerun u test and check the data before and after travelling the warp to make sure the new route has been stored correctly. Sometimes I wish I hadn't made this so complicated but exploring and revealing maps adds much fun to a game.

I decided to put 3 levels of AI in the game for computer ships. Level 1 is an autopilot that just takes over the flight to the current destination in a sector then waits for the player for the next instruction. Its main use will be to fly the ship while you pop into the computer system. It is switched on and off automatically when you enter the computer system but I will also add an auto pilot button which you can to so you can leave the game running to get a cup of coffee.  Level 2 is a full blown AI which will run the ship through a complete mission then wait for the player to choose another mission. Level 3 gives the ships full autonomy to play the game by themselves choosing their own missions but earning money for the player.  The player can change the Ai level or choose to take over control of ships at most times except while warping when their will be no communication.

So when this is working I can let the computer run several tests at once and just take over when I want to see what is happening. This should speed up testing as it takes time to drive all over space to perform a particular task. It will also make the game more fun as you can just play the bits you like and let the computer do the rest.  I hate games where you are forced to repeat mundane things to get to the good bits. I envisage a player having a few mining or freight craft on full AI earning credits to pay for frontline fighting ships where the real action will be.  I cant wait to get this working I feel its very close now.  Soon there will be a growing network of bases, building ships, mining resources. It will grow rapidly until it collides with the Seiddab. Then it will be all out war and the priority will be to defend the space infrastructure to enable more ships to be built.

Things to do:
Test base building, especially AI docking of base pieces.
Test AI player swapping of different stages of missions to make sure they are fully interchangeable.
Code the trading screens to buy/sell resources maybe even shares of factions which are like huge corporations.
Allow the player to become a faction.
Put in all the whizz bang graphic effects.
Do all the in game graphics.
Add sound.
Tune up all constants such as prices, weights, speeds, firepower.
Write an AI squad leader routine.
Complete the faction AI routines that choose bases and ships, perhaps the most complex of the lot but similar to the logic I had in Realms. It used the network of routes between cities as its "gameboard" and looked for neighbours it could beat or had to guard against. Some of this is already in action, for maintaining the infrastructure. I need to put attack and defence strategies in.
I have a diplomacy system worked out and alliances are already coded but it will need a screen to run it.
I need a comms system so messages can be sent to bases , squad members. I rather fancy adding a Cortana/Alexsis type speech control system to command the ships computer but maybe this will have to wait for another version of the game.

Test test and more testing.

Still a considerable amount I better get coding!

Programming Tip.

Programming is complicated. A good programmers mission is to make it as simple to understand as they can. I have said it before but it is so important I will reiterate. To to write a piece of code so that a non coder can understand it. It is not clever to to write clever looking code.

One of the big discussions we had at Graftgold was regarding the coding standards to follow. People tend to pursue there particular preferences with a religious fervour.  In the end I had the final say. I listened to the various views and from them worked out the companies main principals for choosing standards.
1. It was  important to have one way of doing things rather than each programmer have their own style. This enabled programmers to be able to work on each others code. (Without feeling the need to change it all to their own coding preferences).
2. Where possible the standard was chosen to make the code clearer to read, understand and maintain. It did not matter whether that was the way K and R did it.
3. The standard would be agreed ,written down and issued to all programmers.
4.Where there was no agreement or clear best way, I would choose the way that would become standard.

These principals lead to a coherent set of standards that all the programmers accepted and adhered to. This greatly improved the quality of Graftgold code. It increased efficiency after the initial couple of weeks adopting the new style. It was a superb guide for new programmers to show them how to code.
Within a few days lines of C that were unintelligible were not being written anymore. Clearer code lead to fewer errors and allowed multi programmer projects to take place.

We banned confusing things like cramming many C statements on one line  and tertiary operators, mispelt or misleading  data or function names.  We chose the way we would position curly brackets and how many spaces a tab would be. For some things it did not matter what was chosen , just that it would be the same for every piece of code and hence lead to instantly recognisable code that would be displayed correctly on any of our development machines. There are plenty of sources to get set of standards from.  Adopt one or pick and choose the best bits. Just end up with one way of doing things.

So if you do not have a standard way of writing code it is time to adopt a set of standards. Have a set way of coding each type of processing, each C construct, source and header layouts, project layouts, even disk directory layouts. Then you can sit on anyone's machine and instantly be at home. You need a standard layout to enable a central repository and easy recovery of bad disks. Ban non standard editors or modifications from the OS upwards. The idea is that all work stations should be vanilla and interchangeable.


  1. Great stuff!
    I see the baddies are going to be at it again!


Post a Comment

Popular Posts