home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d1xx / d118 / empire.lha / Empire / doc / Changing.doc next >
Text File  |  1987-12-03  |  13KB  |  230 lines

  1.                 Changing Empire
  2.  
  3. The first thing you will notice about Amiga Empire is that it is written in
  4. a "nonstandard" language. That language is Draco, which is a shareware
  5. system available as part of the Fred Fish freely distributable software
  6. collection. Disk 76 in that collection contains the compiler, libraries,
  7. include files, some tools, etc. Disk 77 contains full documentation and
  8. several example programs, along with an early version of Amiga Empire.
  9.  
  10. If you are used to programming in some other language, such as C, Pascal,
  11. Modula-II, Lisp or Forth, your reaction to this will be negative. Why then,
  12. did I chose to program Empire in Draco? The first reason is purely personal
  13. - I designed and programmed Draco, so it is only natural that I prefer to
  14. use it. The second reason is that by using a freely available compiler, the
  15. number of people who can work with Empire is considerably greater. The C
  16. compilers for the Amiga cost upwards of $200. For someone who has bought an
  17. Amiga 500 to play around with, spending that kind of money to work with a
  18. game is probably not an option. A third reason is that I (along with many
  19. other people) consider C a poor language for people learning to program,
  20. and I want to discourage people from trying to learn it as a first
  21. language. At work I program in C all the time, and I spent much of the past
  22. two years building a C compiler to meet the draft ANSI C specification, so
  23. I am quite conversant with the use of C. By providing the reasonably
  24. programmed source to a very popular game in Draco, I hope to encourage
  25. people to try the language out. No doubt someone will come along and
  26. translate Amiga Empire into C, thinking they are doing the world a big
  27. favour. I can't stop that, but I will say that I plan to support the Draco
  28. version, and that I am confident that the Draco version will tend to have
  29. fewer bugs than a C version would.
  30.  
  31.  
  32. The Data Structures
  33.  
  34. There does not exist a design document for this version of Empire.
  35. Currently, the best source of inside information is the accompanying file,
  36. "Deity.doc", which explains some of the data structures that can be changed
  37. by the Deity. Empire doesn't have many complicated data structures. For
  38. example, there are no linked lists, and no storage is dynamically
  39. allocated. In brief, the data structures are as follows:
  40.  
  41.     Sector_t - this structure represents a single sector in the Empire
  42.     world. The world itself is a square array of such sectors. Since
  43.     Empire can handle large worlds (a 128 x 128 world has a couple of
  44.     megabytes worth of sectors), the array is not kept in memory.
  45.     Instead, sectors are kept on disk (in file 'empire.sectors') and
  46.     accessed as needed. An LRU (least recently used) cache of sectors
  47.     keeps the amount of actual disk I/O down. See file 'fileio.d'.
  48.  
  49.     World_t - this structure represents the global structure of the entire
  50.     world. There is only one of these for each Empire game. It contains
  51.     various counters, sizes, etc. as well as all of the Deity-tunable
  52.     parameters. It is stored as the first part of 'empire.sectors'.
  53.  
  54.     Country_t - this structure represents the state of a country within
  55.     Empire. It contains such things as the name of the country, where
  56.     its capital is, how much money it has, which fleets it owns, etc.
  57.     An array (size COUNTRY_MAX) of these is always kept in memory, and
  58.     is stored on disk in 'empire.sectors' after the World_t and before
  59.     the square array of Sector_t's. Thus, the format of file
  60.     'empire.sectors' is:
  61.  
  62.         one World_t
  63.         COUNTRY_MAX Country_t's
  64.         #rows x #columns Sector_t's
  65.  
  66.     The number of rows and columns is stored in the World_t. Note that
  67.     Empire itself does not require a square world, but that is all that
  68.     EmpCre can currently produce. The sectors are stored by row, that
  69.     is, the first row comes first, followed by the second row, etc. The
  70.     first sector in the file is the one with absolute (Deity)
  71.     coordinates 0,0.
  72.  
  73.     Ship_t - this structure represents a ship. They are stored in file
  74.     'empire.ships', with no header, so ship number 0 is at the
  75.     beginning of the file. The number of ships in the world is
  76.     contained in the World_t, so the next free slot is always known.
  77.     Currently, ships are not re-used when they are sunk.
  78.  
  79.     Fleet_t - this structure represents a fleet of ships. Each fleet can
  80.     have FLEET_MAX ships in it, and is pointed to by the Country_t of
  81.     the owning country. Fleets are stored in 'empire.fleets' analagous
  82.     to ships in 'empire.ships'.
  83.  
  84.     Loan_t - this structure represents a loan. They are stored in file
  85.     'empire.loans'.
  86.  
  87.     Offer_t - this structure represents a sale offer, or lot. They are
  88.     stored in file 'empire.offers'. Note that the delivery direction
  89.     fields in an exchange sector are used to point at the offer which
  90.     represents that exchange.
  91.  
  92.     News_t - this small structure represents a news item. They are
  93.     automatically appended to the current day's news file as they are
  94.     generated.
  95.  
  96. Note: there are some major structural differences between this Empire and
  97. the old Peter Langston Empire. Fleets actually exist as structures. This
  98. makes it faster to navigate or examine a fleet of ships since the entire
  99. ship file does not have to be scanned. Items for sale also exist as
  100. distinct structures (Offer_t's). This makes it unneccessary to scan the
  101. ships and/or sectors to produce a trade report. It also made it possible to
  102. separate the functions of the trade report and the buy command. Third, each
  103. sector maintains a count of how many ships are in it. This considerably
  104. speeds up airplane flying by makeing it unneccessary to scan the ship file
  105. for each water sector flown over.
  106.  
  107.  
  108. The Code
  109.  
  110. A number of conventions were followed in Empire, hopefully makeing it
  111. easier to understand. I sincerely hope those who modify it will follow the
  112. same conventions, thus allowing others that come after them the same
  113. chance. They are:
  114.  
  115.     - all command routines are named as 'cmd_' followed by the command.
  116.     - the general parsing routines (in 'parse.d') are named as 'getXXX' or
  117.     'reqXXX' depending on whether they will prompt for a missing value.
  118.     - all type names not built into the language end in '_t'.
  119.     - all structure field names have a 'taglet' on the front which
  120.     indicates which structure they belong to.
  121.     - all constants are written entirely in upper case.
  122.     - all global variables start with an upper-case letter.
  123.     - all local variables start with a lower-case letter.
  124.     - all routines in a given file which are called by routines in another
  125.     file are declared in include file 'empfunc.g'. This allows the
  126.     compiler to check all calls against that declaration, which is in
  127.     turn checked against the actual definition.
  128.     - global variables which are needed only in one file are declared in
  129.     that file, instead of in 'empire.g'.
  130.  
  131. The basic structure of the Empire code is quite straightforward. It spends
  132. most of its time in 'processCommands', looping around reading commands,
  133. looking them up and calling the appropriate 'cmd_' routine.
  134.  
  135. Handling of parameters to commands is conventionalized. Nearly all input
  136. can be given on the command line. If it is not there it will be prompted
  137. for. This is handled by the 'reqXXX' routines - they all take a prompt, and
  138. return a boolean indicating whether or not they got a proper value. If
  139. there is something remaining on the input command line, they look there and
  140. do not print the prompt. If what they find is invalid, they return 'false',
  141. and the command will be aborted. If there is nothing left on the command
  142. line, they print their prompt, and read a value. If an invalid value is
  143. entered, they will reprint the prompt and try again. If no value is entered
  144. (just RETURN is hit), they will return 'false', and the command will be
  145. aborted.
  146.  
  147. Several commands require that a range of sectors or ships be scanned. These
  148. ranges can have match conditions attached to them. These are handled by the
  149. code in 'scan.d'. The key routines there, 'scanSectors' and 'scanShips',
  150. are passed a procedure to call, and take their range from structures
  151. declared and built in 'scan.d'. For each matching sector or ship, they call
  152. the routine passed to them, giving it the sector or ship. A couple of hooks
  153. in there allow an empty specification on the 'ships' command to mean all
  154. ships, and allow a condition on the 'map' command, thus allowing the player
  155. to produce a map showing only those sectors which match the condition.
  156.  
  157. The best way to find out for sure which file a routine is in is to look in
  158. 'empfunc.g'.
  159.  
  160.  
  161. Things To Do
  162.  
  163. A couple of people have suggested that Empire should have graphics (after
  164. all, it's a game for the Amiga, right?). No one who has seriously played it
  165. has suggested it. Most players of Empire will be people who log in over the
  166. modem - they probably don't even HAVE an Amiga. The most useful thing I can
  167. think of is to have a split screen - the top portion displays the latest
  168. map or radar output, and the bottom portion is a normal, scrolling text
  169. area for all other output. Windowing in the top portion and history in the
  170. bottom portion would be useful.
  171.  
  172. A number of people have built tools to use as front ends or batch
  173. processors for Empire. They have ranged from graphical front ends running
  174. on Sun workstations to tools which print maps on laser printers with
  175. borders around the owner's country, and delivery routes shown as arrows. By
  176. all means let's build some of these for the Amiga, and perhaps even combine
  177. them with a terminal program to build a nice front-end to Empire. A word of
  178. caution, however - such programs can change the nature of the game, by
  179. offloading a lot of work from the player to a computer. Make sure that all
  180. players in a game have similar advantages, or agree to the use of the tools
  181. by other players. A related advantage can be had by a player connecting at
  182. 2400 baud (or playing locally) while others are restricted to 300 baud.
  183.  
  184. There should be a built-in facility for a Visitor country which can do
  185. power reports and read the news, but nothing else.
  186.  
  187. Peter Langston Empire has treaties. Should these be implemented in Amiga
  188. Empire? How useful were they?
  189.  
  190. Other versions of Empire have farms, bombers, tanks, nuclear weapons,
  191. "happiness" factors, etc. How much of this should be added? Are you
  192. volunteering?
  193.  
  194. The Amiga is a multi-tasking computer, but Amiga Empire allows only one
  195. person at a time to play. It would be nice to fix this. Even on a normal
  196. Amiga, one player could be playing locally while another was coming in over
  197. the serial port. Serial line multiplexers are available which would let the
  198. Amiga have several people connected at once. Properly done, this would
  199. require locking/unlocking of each resource used (country, sector, ship,
  200. etc.) Going through the Amiga file system would clearly be too slow (the
  201. caches in 'fileio.d' would have to be removed). On the Amiga, a proper
  202. solution might be to have a separate task running as a resource server. It
  203. would contain the caches, and do all file I/O (except perhaps telegrams).
  204. It would be responsible for blocking Empire tasks which wanted access a
  205. resource which someone else was using (or of telling the task that the
  206. resource is unavailable, and have it try again later). Communication would
  207. probably be in the form of messages (Exec is a message passing operating
  208. system after all) - the message to the server would contain a request, and
  209. the reply would contain the locked data, or a notification that the data is
  210. locked by someone else. At first glance, this would appear to be easy to
  211. fit into Amiga Empire, since all requests for sectors, ships, fleets,
  212. loans, offers, news, and telegrams go through routines in 'fileio.d'.
  213. Deadlocks ("deadly embraces") would soon be a problem however. Many of the
  214. Empire routines need more than one resource at different times. For
  215. example, anything that can damage a ship (which is just about anything that
  216. looks at one, since 'updateShip' could sink the ship due to a hurricane)
  217. has to lock the sector it is in to be able to change the shipCount. All of
  218. the fighting commands involve at least two sectors or ships. Imagine the
  219. following: two enemy countries are logged in at the same time and are
  220. attacking each other. They happen to fire guns at the sector which the
  221. other is fireing from. Both lock the fireing sectors (they have to be
  222. prepared for defensive damage, and to decrement the shell count), verify
  223. that they can fire, and then try to lock their target sectors. If the
  224. timeing is just right, both of those will be locked by the other, and they
  225. will sit their forever, waiting for each other to release the sectors.
  226. Special code is needed to handle this (for example, requesting all needed
  227. resources in one message to the server, or being able to back out of all
  228. locks held if a needed lock cannot be gotten). Doing this in all neccessary
  229. places will not be easy. Identifying those places will also be hard.
  230.