home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Games / Xconq 7.1.0 / src / xconq-7.1.0 / kernel / init.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-07  |  38.6 KB  |  1,405 lines  |  [TEXT/R*ch]

  1. /* General Xconq initialization.
  2.    Copyright (C) 1987, 1988, 1989, 1991, 1992, 1993, 1994, 1995, 1996
  3.    Stanley T. Shebs.
  4.  
  5. Xconq is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2, or (at your option)
  8. any later version.  See the file COPYING.  */
  9.  
  10. /* Initialization is complicated, because Xconq needs lots of setup for
  11.    maps, units, sides, and the like.  The data must also be able to come
  12.    from saved games, scenarios, bare maps in files, type definitions,
  13.    or be synthesized if necessary. */
  14.  
  15. /* The general theory is that everything gets set to a known empty state,
  16.    then all files are read, then all the synthesis methods get run.
  17.    Files/readers and synth methods are each responsible for preventing
  18.    fatal conflicts. */
  19.  
  20. #include "conq.h"
  21. extern void add_library_path PARAMS ((char *path));
  22. extern void prealloc_debug PARAMS ((void));
  23. #include "version.h"
  24.  
  25. static void cache_possible_types PARAMS ((void));
  26. static void trial_assign_player PARAMS ((int i, Player *player));
  27. static void init_view_2 PARAMS ((Side *side, int terrainset));
  28. static void init_view_cell PARAMS ((int x, int y));
  29. static void maybe_init_view_cell PARAMS ((int x, int y));
  30. static int adj_seen_terrain PARAMS ((int x, int y, Side *side));
  31.  
  32. /* This is true when the set of types has been defined.  Subsequently only
  33.    scenarios based on those types can be loaded. */
  34.  
  35. int typesdefined = FALSE;
  36.  
  37. /* This is true after the game is totally synthesized, but players may
  38.    not all be in the game yet. */
  39.  
  40. int gamedefined = FALSE;
  41.  
  42. /* These are handy tmp vars, usually used with function args. */
  43.  
  44. short tmputype;
  45. short tmpmtype;
  46. short tmpttype;
  47.  
  48. /* The array of player/side matchups. */
  49.  
  50. Assign *assignments = NULL;
  51.  
  52. /* The list of pathnames to library directories. */
  53.  
  54. LibraryPath *xconq_libs;
  55.  
  56. LibraryPath *last_user_xconq_lib;
  57.  
  58. /* The name of the default game module. */
  59.  
  60. char *standard_game_name;
  61.  
  62. /* This is the main string printing buffer.  It is statically allocated
  63.    because it is used even before the main data structures are inited. */
  64.  
  65. char spbuf[BUFSIZE];
  66.  
  67. /* This is an auxiliary buffer.  Also needs to be statically allocated. */
  68.  
  69. char tmpbuf[BUFSIZE];
  70.  
  71. /* This is true if the interface was requested to put up a new game
  72.    dialog (kind of a random file for this, but *is* init-related). */
  73.  
  74. int option_popup_new_game_dialog;
  75.  
  76. #ifdef DESIGNERS
  77.  
  78. /* This is true if all sides with displays should become designers
  79.    automatically. */
  80.  
  81. int allbedesigners = FALSE;
  82.  
  83. /* This is the current count of how many sides are designers. */
  84.  
  85. int numdesigners = 0;
  86.  
  87. #endif /* DESIGNERS */
  88.  
  89. int max_zoc_range;
  90.  
  91. short *u_possible;
  92.  
  93. /* The table of all available synthesis methods. */
  94.  
  95. struct synthtype {
  96.     int key;
  97.     int (*fn) PARAMS ((int calls, int runs));
  98.     int dflt;
  99.     int calls;
  100.     int runs;
  101. } synthmethods[] = {
  102.     { K_MAKE_FRACTAL_PTILE_TERRAIN, make_fractal_terrain, TRUE, 0, 0 },
  103.     { K_MAKE_RANDOM_TERRAIN, make_random_terrain, FALSE, 0, 0 },
  104.     { K_MAKE_EARTHLIKE_TERRAIN, make_earthlike_terrain, FALSE, 0, 0 },
  105.     { K_MAKE_MAZE_TERRAIN, make_maze_terrain, FALSE, 0, 0 },
  106.     { K_MAKE_RIVERS, make_rivers, TRUE, 0, 0 },
  107.     { K_MAKE_COUNTRIES, make_countries, TRUE, 0, 0 },
  108.     { K_MAKE_INDEPENDENT_UNITS, make_independent_units, TRUE, 0, 0 },
  109.     { K_MAKE_INITIAL_MATERIALS, make_initial_materials, TRUE, 0, 0 },
  110.     { K_NAME_UNITS_RANDOMLY, name_units_randomly, TRUE, 0, 0 },
  111.     { K_NAME_GEOGRAPHICAL_FEATURES, name_geographical_features, TRUE, 0, 0 },
  112.     { K_MAKE_ROADS, make_roads, TRUE, 0, 0 },
  113.     { K_MAKE_WEATHER, make_weather, TRUE, 0, 0 },
  114.     { K_MAKE_RANDOM_DATE, make_random_date, FALSE, 0, 0 },
  115.     { -1, NULL, 0, 0, 0 }
  116. };
  117.  
  118. /* Allow environment vars to override compiled-in library and game. */
  119.  
  120. void
  121. init_library_path(path)
  122. char *path;
  123. {
  124.     char *xconqlib;
  125.  
  126.     xconqlib = getenv("XCONQLIB");
  127.     if (empty_string(xconqlib)) {
  128.     if (!empty_string(path)) {
  129.         xconqlib = path;
  130.     } else {
  131.         xconqlib = default_library_filename();
  132.     }
  133.     }
  134.     xconq_libs = (LibraryPath *) xmalloc(sizeof(LibraryPath));
  135.     xconq_libs->path = copy_string(xconqlib);
  136.     last_user_xconq_lib = NULL;
  137.     standard_game_name = getenv("XCONQSTANDARDGAME");
  138.     if (empty_string(standard_game_name))
  139.       standard_game_name = STANDARD_GAME;
  140. }
  141.  
  142. void
  143. add_library_path(path)
  144. char *path;
  145. {
  146.     LibraryPath *lib;
  147.  
  148.     /* A NULL path indicates that all the existing paths should go away. */
  149.     if (path == NULL) {
  150.     xconq_libs = last_user_xconq_lib = NULL;
  151.     return;
  152.     }
  153.     lib = (LibraryPath *) xmalloc(sizeof(LibraryPath));
  154.     lib->path = copy_string(path);
  155.     /* Insert this after the previous user-specified library, if there
  156.        was any, but before the default library places. */
  157.     if (last_user_xconq_lib != NULL) {
  158.     lib->next = last_user_xconq_lib->next;
  159.     last_user_xconq_lib->next = lib;
  160.     } else {
  161.     lib->next = xconq_libs;
  162.     xconq_libs = lib;
  163.     }
  164.     last_user_xconq_lib = lib;
  165. }
  166.  
  167. /* This is a general init that prepares data structures to be filled in
  168.    by a game definition.  It should run *before* command line parsing. */
  169.  
  170. void
  171. init_data_structures()
  172. {
  173.     init_xrandom(-1);
  174.     init_lisp();
  175.     init_types();
  176.     init_globals();
  177.     init_namers();
  178.     init_world();
  179.     init_history();
  180.     init_sides();
  181.     init_agreements();
  182.     init_units();
  183.     init_nlang();
  184.     init_help();
  185.     init_scorekeepers();
  186.     init_actions();
  187.     init_tasks();
  188.     init_ai_types();
  189.     init_write();
  190. }
  191.  
  192. /* Build the default list of synthesis methods. */
  193.  
  194. void
  195. set_g_synth_methods_default()
  196. {
  197.     int i;
  198.     Obj *synthlist = lispnil, *synthlistend = lispnil, *tmp;
  199.  
  200.     for (i = 0; synthmethods[i].key >= 0; ++i) {
  201.     if (synthmethods[i].dflt) {
  202.         tmp = cons(intern_symbol(keyword_name(synthmethods[i].key)),
  203.                lispnil);
  204.         if (synthlist == lispnil) {
  205.         synthlist = synthlistend = tmp;
  206.         } else {
  207.         set_cdr(synthlistend, tmp);
  208.         synthlistend = tmp;
  209.         }
  210.     }
  211.     }
  212.     /* Now alter the global variable to contain this list. */
  213.     set_g_synth_methods(synthlist);
  214. }
  215.  
  216. /* Run a doublecheck on plausibility of game parameters.  Additional
  217.    checks are performed elsewhere as needed, for instance during random
  218.    generation.  Serious mistakes exit now, since they can cause all sorts
  219.    of strange behavior and core dumps.  It's a little more friendly to only
  220.    exit at the end of the tests, so all the mistakes can be found at once. */
  221.  
  222. /* In theory, if a game passes these tests, then Xconq will never crash. */
  223.  
  224. /* (This should always be run, might find errors in compiled game.) */
  225.  
  226. void
  227. check_game_validity()
  228. {
  229.     int failed = FALSE, movers = FALSE, actors = FALSE;
  230.     int u1, u2, m1, t1, t2;
  231.  
  232.     /* We must have at least one kind of unit. */
  233.     if (numutypes < 1) {
  234.     init_error("no unit types have been defined");
  235.     failed = TRUE;
  236.     }
  237.     /* OK not to have any types of materials. */
  238.     /* We must have at least one kind of terrain. */
  239.     if (numttypes < 1) {
  240.     init_error("no terrain types have been defined");
  241.     failed = TRUE;
  242.     }
  243.     /* Make sure inter-country distances relate correctly. */
  244.     if (g_separation_min() >= 0
  245.     && g_separation_max() >= 0
  246.     && !(g_separation_min() <= g_separation_max())) {
  247.     init_warning("country separations %d to %d screwed up",
  248.              g_separation_min(), g_separation_max());
  249.     }
  250.  
  251.     /* (Need more general game checks.) */
  252.  
  253.     max_zoc_range = -1;
  254.     /* Check that all the unit names and chars are distinct. */
  255.     for_all_unit_types(u1) {
  256.     for_all_unit_types(u2) {
  257.         /* Only do "upper triangle" of utype x utype matrix. */
  258.         if (u1 < u2) {
  259.         if (strcmp(u_type_name(u1), u_type_name(u2)) == 0) {
  260.             init_warning(
  261.              "unit types %d and %d are both named \"%s\"",
  262.                  u1, u2, u_type_name(u1));
  263.             /* This is bad but not disastrous, so don't fail. */
  264.         }
  265.         }
  266.         if (uu_zoc_range(u1, u2) > max_zoc_range) {
  267.         max_zoc_range = uu_zoc_range(u1, u2);
  268.         }
  269.     }
  270.     }
  271.     /* Large ZOC ranges are not implemented. */
  272.     if (max_zoc_range > 1) {
  273.     init_warning("ZOC range goes up to %d, may be very inefficient", max_zoc_range);
  274.     }
  275.     /* (Eventually check material types also.) */
  276.     /* Check that all terrain names and chars are distinct. */
  277.     for_all_terrain_types(t1) {
  278.     for_all_terrain_types(t2) {
  279.         /* Only do "upper triangle" of ttype x ttype matrix. */
  280.         if (t1 < t2) {
  281.         if (strcmp(t_type_name(t1), t_type_name(t2)) == 0) {
  282.             init_warning(
  283.              "terrain types %d and %d are both named \"%s\"",
  284.              t1, t2, t_type_name(t1));
  285.             /* This is bad but not disastrous, so don't fail. */
  286.         }
  287.         /* Should check that colors are different from each other
  288.            and from builtin colors? */
  289.         }
  290.     }
  291.     }
  292.     /* Check various unit type properties. */
  293.     for_all_unit_types(u1) {
  294.     /* Can't make use of this yet, so error out if anybody tries. */
  295.     if (u_available(u1) != 1) {
  296.         init_error("unit type %d must always be available", u1);
  297.         failed = TRUE;
  298.     }
  299.     /* Can't make use of this yet, so error out if anybody tries. */
  300.     if (u_action_priority(u1) != 0) {
  301.         init_error("unit type %d cannot have a nonzero action priority", u1);
  302.         failed = TRUE;
  303.     }
  304.     /* should be part of general bounds check */
  305.     if (u_cp(u1) <= 0) {
  306.         init_error("unit type %d has nonpositive cp", u1);
  307.         failed = TRUE;
  308.     }
  309.     if (u_hp(u1) <= 0) {
  310.         init_error("unit type %d has nonpositive hp", u1);
  311.         failed = TRUE;
  312.     }
  313.     if (u_parts(u1) <= 0) {
  314.         init_error("unit type %d has nonpositive part count.", u1);
  315.         failed = TRUE;
  316.     }
  317.     if (u_parts(u1) > 0 && u_hp(u1) % u_parts(u1) != 0) {
  318.         init_error("unit type %d hp not a multiple of its parts.", u1);
  319.         failed = TRUE;
  320.     }
  321.     if (u_speed(u1) > 0) {
  322.         movers = TRUE;
  323.     }
  324.     if (u_acp(u1) > 0) {
  325.         actors = TRUE;
  326.     }
  327.     }
  328.     /* Check various material type properties. */
  329.     for_all_material_types(m1) {
  330.     /* Can't make use of this yet, so error out if anybody tries. */
  331.     if (m_available(m1) != 1) {
  332.         init_error("material type %d not always available", m1);
  333.         failed = TRUE;
  334.     }
  335.     }
  336.     /* Check various terrain type properties. */
  337.     for_all_terrain_types(t1) {
  338.     /* Can't make use of this yet, so error out if anybody tries. */
  339.     if (t_available(t1) != 1) {
  340.         init_error("terrain type %d not always available", t1);
  341.         failed = TRUE;
  342.     }
  343.     }
  344.     /* If nothing can move and nothing can build, this will probably be
  345.        a really dull game, but there may be such games, do don't say
  346.        anything normally. */
  347.     if (numutypes > 0 && !actors) {
  348.     Dprintf("No actors have been defined.\n");
  349.     }
  350.     if (numutypes > 0 && !movers) {
  351.     Dprintf("No movers have been defined.\n");
  352.     }
  353.     if (numttypes > 0 && numcelltypes == 0) {
  354.     init_error("no terrain type has been allowed for cells");
  355.     failed = TRUE;
  356.     }
  357.     /* This is a really bad game definition, leave before we crash.  This would
  358.        only be executed on systems where init_error doesn't exit immediately. */
  359.     if (failed) {
  360.     exit(0);
  361.     }
  362.     Dprintf("Finished checking game design.\n");
  363.     Dprintf("It defines %d unit types, %d material types, %d terrain types.\n",
  364.         numutypes, nummtypes, numttypes);
  365. }
  366.  
  367. /* Calculate the values of global variables that are used everywhere. */
  368.  
  369. void
  370. calculate_globals()
  371. {
  372.     /* The game is now completely defined; no further user-specified changes can
  373.        occur. */
  374.     gamedefined = TRUE;
  375.     calculate_world_globals();
  376.     /* This needs to be precalculated instead of as-needed, since range can be
  377.        validly both negative and positive, so no way to distinguish uninitialized. */
  378.     {
  379.     int u1, u2, range;
  380.         extern int max_detonate_on_approach_range;
  381.  
  382.     max_detonate_on_approach_range = -1;
  383.     for_all_unit_types(u1) {
  384.         for_all_unit_types(u2) {
  385.         range = uu_detonate_approach_range(u1, u2);
  386.         max_detonate_on_approach_range = max(range, max_detonate_on_approach_range);
  387.         }
  388.     }
  389.     }    
  390. }
  391.  
  392. /* Clean up all the objects and cross-references. */
  393.  
  394. void
  395. patch_object_references()
  396. {
  397.     int numhere, numoccs;
  398.     Unit *unit, *transport;
  399.     Side *side;
  400.     Obj *utref, *utorig;
  401.  
  402.     /* Use read-in ids to fill in side slots that point to other objects. */
  403.     for_all_sides(side) {
  404.     if (side->playerid > 0) {
  405.         side->player = find_player(side->playerid);
  406.     }
  407.     if (side->controlled_by_id > 0) {
  408.         side->controlled_by = side_n(side->controlled_by_id);
  409.     }
  410.     if (side->self_unit_id > 0) {
  411.         side->self_unit = find_unit(side->self_unit_id);
  412.     }
  413.     }
  414.     for_all_units(unit) {
  415.     /* It's possible that dead units got read in, so check. */
  416.     if (alive(unit)) {
  417.         if (unit->transport != NULL) {
  418.         transport = NULL;
  419.         utref = utorig = (Obj *) unit->transport;
  420.         /* For safety's sake, null out the slot. */
  421.         unit->transport = NULL;
  422.         /* We have a Lisp object; use it to identify a particular
  423.            unit as the transport. */
  424.         if (symbolp(utref) && boundp(utref)) {
  425.             utref = symbol_value(utref);
  426.         }
  427.         if (numberp(utref)) {
  428.             transport = find_unit(c_number(utref));
  429.             if (transport == NULL)
  430.               init_warning("could not find a transport id %d for %s",
  431.                    c_number(utref), unit_desig(unit));
  432.         } else if (stringp(utref)) {
  433.             transport = find_unit_by_name(c_string(utref));
  434.             if (transport == NULL)
  435.               init_warning("could not find a transport named \"%s\" for %s",
  436.                    c_string(utref), unit_desig(unit));
  437.         } else {
  438.             /* not a recognized way to refer to a unit */
  439.             sprintlisp(tmpbuf, utorig);
  440.             init_warning("could not find transport %s for %s",
  441.                  tmpbuf, unit_desig(unit));
  442.         }
  443.         /* it is important to make sure that unit->x, and unit->y 
  444.            are negative at this point.  Otherwise, the coverage will
  445.            be messed up for units put into transports that have not yet
  446.            been placed.  They will be covered for entering the cell,
  447.            and again when the transport enters the cell. */
  448.         if (transport != NULL) {
  449.             /* (also check that this is a valid transport type?) */
  450.             enter_transport(unit, transport);
  451.         } else {
  452.             /* (could let the unit enter the cell, or could
  453.                make it infinitely postponed) */
  454.         }
  455.         } else {
  456.         /* Check that the unit's location is meaningful. */
  457.         if (!inside_area(unit->x, unit->y)) {
  458.             if (inside_area(unit->prevx, unit->prevy)) {
  459.             if (can_occupy_cell(unit, unit->prevx, unit->prevy)) {
  460.                 enter_cell(unit, unit->prevx, unit->prevy);
  461.             } else {
  462.                 numhere = numoccs = 0;
  463.                 /* Search this cell for units to enter. */
  464.                 for_all_stack(unit->prevx, unit->prevy, transport) {
  465.                 ++numhere;
  466.                 if (unit->side == transport->side
  467.                     && can_occupy(unit, transport)) {
  468.                     enter_transport(unit, transport);
  469.                     break;
  470.                 }
  471.                 if (unit->side == transport->side
  472.                     && can_occupy(transport, unit))
  473.                   ++numoccs;
  474.                 }
  475. #if 0
  476.                 /* Try having all the existing units enter the transport. */
  477.                 /* (but doesn't work if only some units should go into transport) */
  478.                 if (!inside_area(unit->x, unit->y) && numoccs == numhere) {
  479.                 for_all_stack(unit->prevx, unit->prevy, unit2) {
  480.                     enter_transport(unit2, unit);
  481.                 }
  482.                 enter_cell(unit, unit->prevx, unit->prevy);
  483.                 }
  484. #endif
  485.                 if (!inside_area(unit->x, unit->y)) {
  486.                 init_warning("No room for %s at %d,%d",
  487.                          unit_desig(unit),
  488.                          unit->prevx, unit->prevy);
  489.                 }
  490.             }
  491.             /* This prevents attempts to do a second enter_cell
  492.                during initialization. */
  493.             unit->prevx = unit->prevy = -1;
  494.             } else if (unit->prevx == -1 && unit->prevy == -1) {
  495.                 /* This will be left alone - should have pos filled in later. */
  496.             } else if (unit->cp >= 0) {
  497.             /* Warn, but only if there's no good reason for the unit to have
  498.                an offworld position. */
  499.             if (area.fullwidth == 0) {
  500.                 init_warning("%s is at offworld location, left there",
  501.                      unit_desig(unit));
  502.             }
  503.             /* This will make it be a reinforcement. */
  504.             unit->cp = -1;
  505.             }
  506.         }
  507.         }
  508.         /* Make sure that side numbering will use only new numbers. */
  509.         if (unit->side != NULL) {
  510.         if (unit->number > 0) {
  511.             (unit->side->counts)[unit->type] =
  512.               max((unit->side->counts)[unit->type], 1 + unit->number);
  513.         }
  514.         } else {
  515.         /* Trash the numbers on indep units. */
  516.         unit->number = 0;
  517.         }
  518.         if (completed(unit)) {
  519.         init_unit_actorstate(unit, TRUE);
  520.         /* Restore acp that wasn't written out because it was the most normal
  521.            value. */
  522.         if (unit->act && unit->act->acp < u_acp_min(unit->type))
  523.           unit->act->acp = u_acp(unit->type);
  524.         /* Restore initacp that wasn't written out because it was the normal
  525.            value. */
  526.         if (unit->act
  527.             && unit->act->acp > 0
  528.             && unit->act->initacp == 0)
  529.           unit->act->initacp = u_acp(unit->type);
  530.         /* Might already have a plan, leave alone if so. */
  531.         if (unit->plan == NULL) {
  532.             init_unit_plan(unit);
  533.         }
  534.         }
  535.     } else {
  536.         /* Dead units need to be disentangled from anything that might
  537.            have been done to them.  For instance, a module might include
  538.            a standard collection of units, but then follow up by removing
  539.            some of those units, and can do it by setting hp == 0.  We want
  540.            this to work consistently and reliably. */
  541.         /* Null this out, any possible unit reference is useless. */
  542.         unit->transport = NULL;
  543.         if (inside_area(unit->x, unit->y)) {
  544.         leave_cell(unit);
  545.         }
  546.     }
  547.     }
  548. }
  549.  
  550. /* Make up a proposed side/player assignment, creating sides and players
  551.    as necessary.  Lock down any assignments that should not be changed,
  552.    but leave everything to be changed as desired. */
  553.  
  554. /* (when does locking get done?) */
  555.  
  556. void
  557. make_trial_assignments()
  558. {
  559.     int i = 0;
  560.     Side *side;
  561.     Player *player;
  562.  
  563.     /* Fill in the side's predefined default and range of initial advantage. */
  564.     for_all_sides(side) {
  565.         init_side_advantage(side);
  566.     }
  567.     /* Ensure we have as many sides as will be required. */
  568.     while (numsides < g_sides_min()) {
  569.     make_up_a_side();
  570.     }
  571.     while (numsides < min(numplayers, g_sides_max())) {
  572.     make_up_a_side();
  573.     }
  574.     /* Put in all the sides. */
  575.     for_all_sides(side) {
  576.     assignments[i++].side = side;
  577.     }
  578.     /* If no players have been created, make one that is human-run,
  579.        presumably by the person who started up this program. */
  580.     if (numplayers == 0) {
  581.     add_default_player();
  582.     }
  583.     if (numsides < numplayers) {
  584.     /* We have too many players. */
  585.     init_warning("too many players (%d) for %d sides, ignoring extra",
  586.              numplayers, numsides);
  587.     }
  588.     /* Make any prespecified assignments. */
  589.     for (i = 0; i < numsides; ++i) {
  590.     if (assignments[i].side != NULL
  591.         && assignments[i].side->player != NULL
  592.         && assignments[i].player == NULL) {
  593.         trial_assign_player(i, assignments[i].side->player);
  594.         /* (should this assignment be locked?) */
  595.     }
  596.     }
  597.     /* Assign any remaining players. */
  598.     player = playerlist;
  599.     for (i = 0; i < numsides; ++i) {
  600.     if (assignments[i].side != NULL
  601.         && assignments[i].side->ingame
  602.         && assignments[i].player == NULL) {
  603.         for (; player != NULL; player = player->next) {
  604.         if (player->side == NULL) {
  605.             trial_assign_player(i, player);
  606.             break;
  607.         }
  608.         }
  609.     }
  610.     }
  611.     /* Add default players for sides with none (in separate loop so player
  612.        creation doesn't confuse player list traversal above). */
  613.     for (i = 0; i < numsides; ++i) {
  614.     if (assignments[i].side != NULL
  615.         && assignments[i].player == NULL) {
  616.         player = add_player();
  617.         /* Default players are always AIs (at least for now). */
  618.         player->aitypename = "mplayer";
  619.         trial_assign_player(i, player);
  620.     }
  621.     }
  622.     for_all_players(player) {
  623.     if (player->side == NULL) {
  624.         init_warning("Player %s not given a side", player_desig(player));
  625.     }
  626.     }
  627.     /* At this point, we have matching sides and players, ready to be
  628.        rearranged if desired. */
  629. }
  630.  
  631. static void
  632. trial_assign_player(i, player)
  633. int i;
  634. Player *player;
  635. {
  636.     assignments[i].player = player;
  637.     player->side = assignments[i].side;
  638.     (assignments[i].side)->player = player;
  639.     /* Set the player's advantage to be the side's advantage, if defined. */
  640.     if (assignments[i].player != NULL
  641.     && assignments[i].player->advantage == 0) {
  642.     assignments[i].player->advantage = assignments[i].side->advantage;
  643.     }
  644.     Dprintf("Tentatively assigned %s to %s%s\n",
  645.         side_desig(assignments[i].side),
  646.         player_desig(assignments[i].player),
  647.         (assignments[i].locked ? " (locked)" : ""));
  648. }
  649.  
  650. /* Create a random side with default characteristics. */
  651.  
  652. Side *
  653. make_up_a_side()
  654. {
  655.     extern Obj *side_defaults;
  656.  
  657.     Side *side = create_side();
  658.  
  659.     if (side == NULL) {
  660.     run_error("could not create a side");
  661.     return NULL;
  662.     }
  663.     fill_in_side(side, side_defaults, FALSE);
  664.     make_up_side_name(side);
  665.     init_side_advantage(side);
  666.     /* A newly-created side starts out in the game, can drop out later. */
  667.     side->ingame = TRUE;
  668.     Dprintf("Made up a side %s\n", side_desig(side));
  669.     return side;
  670. }
  671.  
  672. /* If undefined, seed a side's advantage and allowable range from the
  673.    global values. */
  674.  
  675. void
  676. init_side_advantage(side)
  677. Side *side;
  678. {
  679.     /* Set up the default and range of initial advantages. */
  680.     if (side->advantage == 0)
  681.       side->advantage = g_advantage_default();
  682.     if (side->minadvantage == 0)
  683.       side->minadvantage = g_advantage_min();
  684.     if (side->maxadvantage == 0)
  685.       side->maxadvantage = g_advantage_max();
  686. }
  687.  
  688. /* Add a side and a player to go with it (used by interfaces). */
  689.  
  690. int
  691. add_side_and_player()
  692. {
  693.     int n;
  694.     Side *side;
  695.     Player *player;
  696.  
  697.     side = make_up_a_side();
  698.     if (side == NULL)
  699.       return FALSE;
  700.     n = numsides - 1;
  701.     assignments[n].side = side;
  702.     player = add_player();
  703.     assignments[n].player = player;
  704.     player->side = assignments[n].side;
  705.     (assignments[n].side)->player = player;
  706.     /* Set the player's advantage to be the side's advantage, if not
  707.        already set. */
  708.     if (player->advantage == 0) {
  709.     player->advantage = side->advantage;
  710.     }
  711.     return TRUE;
  712. }
  713.  
  714. /* This can be used by interfaces to exchange players between one side and
  715.    another. */
  716.  
  717. int
  718. exchange_players(n, n2)
  719. int n, n2;
  720. {
  721.     int i;
  722.     Player *tmpplayer = assignments[n].player;
  723.  
  724.     if (n < 0)
  725.       n = 0;
  726.     if (n2 < 0) {
  727.     for (i = n + 1; i <= numsides + n; ++i) {
  728.         n2 = i % numsides;
  729.         if (assignments[n2].side && (assignments[n2].side)->ingame)
  730.           break;
  731.     }
  732.     /* No sides to exchange with, return. */
  733.         if (i == numsides + n)
  734.       return -1;
  735.     }
  736.     assignments[n].player = assignments[n2].player;
  737.     assignments[n2].player = tmpplayer;
  738.     /* Doesn't seem like these should be needed, but they are. */
  739.     assignments[n].player->side = assignments[n].side;
  740.     assignments[n].side->player = assignments[n].player;
  741.     assignments[n2].player->side = assignments[n2].side;
  742.     assignments[n2].side->player = assignments[n2].player;
  743.     return n2;
  744. }
  745.  
  746. int
  747. remove_side_and_player()
  748. {
  749.     /* (how to do this?) */
  750.     /* (would need to renumber sides etc) */
  751.     return FALSE;
  752. }
  753.  
  754. /* Synthesis methods fill in whatever is not fixed by game modules or by
  755.    the player(s). */
  756.  
  757. void
  758. run_synth_methods()
  759. {
  760.     int i, methkey, found = FALSE, rslt;
  761.     Obj *synthlist, *methods, *method, *parms;
  762.  
  763.     synthlist = g_synth_methods();
  764.     Dprintf("Will run syntheses ");
  765.     Dprintlisp(synthlist);
  766.     Dprintf("\n");
  767.     for (methods = synthlist; methods != lispnil; methods = cdr(methods)) {
  768.     method = car(methods);
  769.     if (symbolp(method)) {
  770.         methkey = keyword_code(c_string(method));
  771.         for (i = 0; synthmethods[i].key >= 0; ++i) {
  772.         if (methkey == synthmethods[i].key) {
  773.             found = TRUE;
  774.             rslt = (*synthmethods[i].fn)(synthmethods[i].calls, synthmethods[i].runs);
  775.             ++(synthmethods[i].calls);
  776.             if (rslt)
  777.               ++(synthmethods[i].runs);
  778.             break;
  779.         }
  780.         }
  781.     } else if (consp(method)) {
  782.         parms = cdr(method);
  783.         if (stringp(car(method))) {
  784.         /* External program. */
  785.         /* (should format parms, compose outputfile redirection,
  786.             call program with os.c function, check return code,
  787.             open and read output file) */
  788.         run_error("No external synth programs yet");
  789.         }
  790.     }
  791.     if (!found) {
  792.         sprintlisp(spbuf, method);
  793.         init_warning("bad synthesis method %s, ignoring", spbuf);
  794.     }
  795.     }
  796. }
  797.  
  798. int
  799. get_synth_method_uses(methkey, calls, runs)
  800. int methkey, *calls, *runs;
  801. {
  802.     int i;
  803.  
  804.     for (i = 0; synthmethods[i].key >= 0; ++i) {
  805.     if (methkey == synthmethods[i].key) {
  806.         *calls = synthmethods[i].calls;
  807.         *runs = synthmethods[i].runs;
  808.         return TRUE;
  809.     }
  810.     }
  811.     return FALSE;
  812. }
  813.  
  814. int
  815. make_weather(calls, runs)
  816. int calls, runs;
  817. {
  818.     int x, y, winddir;
  819.     extern int maxwindforce;    
  820.  
  821.     if (maxwindforce > 0) {
  822.     if (!winds_defined()) {
  823.         allocate_area_winds();
  824.         if (g_wind_mix_range() > 0) {
  825.         /* Make all winds start in the same direction. */
  826.         /* Initial variation will randomize. */
  827.         winddir = random_dir();
  828.         for_all_cells(x, y) {
  829.             set_wind_at(x, y, winddir,
  830.                 t_wind_force_avg(terrain_at(x, y)));
  831.         }
  832.         } else {
  833.         for_all_cells(x, y) {
  834.             set_wind_at(x, y, random_dir(),
  835.                 t_wind_force_avg(terrain_at(x, y)));
  836.         }
  837.         }
  838.     }
  839.     }
  840.     return TRUE;
  841. }
  842.  
  843. /* Set the starting date/time to a random value within a given range. */
  844.  
  845. int
  846. make_random_date(calls, runs)
  847. int calls, runs;
  848. {
  849.     int n;
  850.  
  851.     /* Don't bother if the initial date has been set explicitly. */
  852.     if (!empty_string(g_initial_date()))
  853.       return FALSE;
  854.     if (empty_string(g_initial_date_min()))
  855.       return FALSE;
  856.     if (empty_string(g_initial_date_max()))
  857.       return FALSE;
  858.     /* Use the low end of the date range as a starting place for date
  859.        calculations. */
  860.     set_initial_date(g_initial_date_min());
  861.     n = turns_between(g_initial_date_min(), g_initial_date_max());
  862.     /* Now bump the starting date to its random place. */
  863.     set_initial_date(absolute_date_string(xrandom(n) + 1));
  864.     return TRUE;
  865. }
  866.  
  867. /* The final init cleans up various stuff. */
  868.  
  869. void
  870. final_init()
  871. {
  872.     Side *side;
  873.  
  874.     /* Fill in any empty doctrines. */
  875.     for_all_sides_plus_indep(side) {
  876.     init_doctrine(side);
  877.     }
  878.     /* Make sure each side has a self-unit if it needs one. */
  879.     for_all_sides(side) {
  880.     init_self_unit(side);
  881.     }
  882.     /* At this point we should be ready to roll.  Any inconsistencies
  883.        hereafter will be fatal. */
  884.     check_consistency();
  885.     cache_possible_types();
  886.     /* Count the units initially present. */
  887.     init_side_balance();
  888.     /* Fix up garbled view data. */
  889.     init_all_views();
  890.     configure_sides();
  891.     /* Check again, just to be sure. */
  892.     check_consistency();
  893.     create_game_help_nodes();
  894.     /* Set up the scores to be attached to each side. */
  895.     init_scores();
  896.     /* Calculate which random event methods will be run. */
  897.     init_random_events();
  898.     final_init_world();
  899.     /* Start the recording of history. */
  900.     start_history();
  901. #ifdef DEBUGGING
  902.     /* Make sure that any debugging-related allocation is done. */
  903.     if (Debug || DebugG || DebugM)
  904.       prealloc_debug();
  905.     /* Report on memory consumption. */
  906.     Dprintf("One side is %d bytes.\n", sizeof(Side));
  907.     Dprintf("One unit is %d bytes, one plan is %d bytes.\n",
  908.         sizeof(Unit), sizeof(Plan));
  909.     if (Debug)
  910.       report_malloc();
  911. #endif /* DEBUGGING */
  912. }
  913.  
  914. /* Load up any player-specified configuration data. */
  915.  
  916. void
  917. configure_sides()
  918. {
  919.     Side *side;
  920.  
  921.     for_all_sides(side) {
  922.     load_side_config(side);
  923.     }
  924. }
  925.  
  926. /* Calculate what each side knows about the world. */
  927.  
  928. void
  929. init_all_views()
  930. {
  931.     int x, y, i = 0, todo = max(1, numsides * area.numcells);
  932.     int terrainset;
  933.     Side *side;
  934.  
  935.     /* Snapshot the value here, so is permanently on. */
  936.     all_see_all = g_see_all();
  937.     /* Set up the basic view structures for all sides first. */
  938.     for_all_sides(side) {
  939.     if (all_see_all) {
  940.         side->see_all = TRUE;
  941.     } else {
  942.         side->see_all = FALSE;
  943.         terrainset = init_view(side);
  944.         init_view_2(side, terrainset);
  945.     }
  946.     /* We're not normally allowed to choose whether to see all or not. */
  947.     side->may_set_see_all = FALSE;
  948.     /* Can't think of any other place to put this... */
  949.     calc_start_xy(side);
  950.     }
  951.     /* Nothing more to do here. */
  952.     if (all_see_all)
  953.       return;
  954.     announce_lengthy_process("Computing current view at each location");
  955.     /* (coverage is also done at this point) */
  956.     for_all_sides(side) {
  957.     for_all_cells(x, y) {
  958.         ++i;
  959.             if (i % 100 == 0)
  960.               announce_progress((100 * i) / todo);
  961.         see_cell(side, x, y);
  962.     }
  963.     }
  964.     finish_lengthy_process();
  965.     init_area_views();
  966. }
  967.  
  968. static void
  969. init_view_2(side, terrainset)
  970. Side *side;
  971. int terrainset;
  972. {
  973.     int x, y;
  974.  
  975.     calc_coverage(side);
  976.     tmpside = side;
  977.     if (g_terrain_seen()) {
  978.     for_all_cells(x, y) {
  979.         init_view_cell(x, y);
  980.     }
  981.     } else {
  982.     for_all_cells(x, y) {
  983.         if (!terrainset)
  984.           set_terrain_view(side, x, y, UNSEEN);
  985.         set_unit_view(side, x, y, EMPTY);
  986.         /* View date is 0, which is what we want. */
  987.     }
  988.     }
  989. }
  990.  
  991. /* This is a helper for the following routine.  The helper is applied to
  992.    each cell, decides what is visible in that cell. */
  993.  
  994. /* This only works from already_seen, does not account for coverage. */
  995.  
  996. /* (should only be run once/cell/side, use a scratch layer to keep track?) */
  997.  
  998. static void
  999. init_view_cell(x, y)
  1000. int x, y;
  1001. {
  1002.     int u, chance;
  1003.     Unit *unit;
  1004.  
  1005.     /* Guaranteed to see the terrain accurately. */
  1006.     set_terrain_view(tmpside, x, y, buildtview(terrain_at(x, y)));
  1007.     /* If this cell is under observation, don't need to do anything special. */
  1008.     if (cover(tmpside, x, y) > 0)
  1009.       return;
  1010.     /* Scan all the units here to see if any are visible. */
  1011.     for_all_stack(x, y, unit) {
  1012.         if (in_play(unit)) {
  1013.             u = unit->type;
  1014.         if (u_see_always(u)) {
  1015.             see_exact(tmpside, x, y);
  1016.             /* or flag unit as spotted? */
  1017.         set_cover(tmpside, x, y, 1);
  1018.             return;
  1019.         }
  1020.         chance = (indep(unit) ? u_already_seen_indep(u)
  1021.               : u_already_seen(u));
  1022.         if (probability(chance)) {
  1023.             see_exact(tmpside, x, y);
  1024.             /* This view might be overwritten by a view of
  1025.                another might-be-seen unit at this location,
  1026.                so don't return just yet. */
  1027.         }
  1028.     }
  1029.     }
  1030.     /* We get to see the weather conditions here. */
  1031.     set_wind_view(tmpside, x, y, raw_wind_at(x, y));
  1032. }
  1033.  
  1034. static void
  1035. maybe_init_view_cell(x, y)
  1036. int x, y;
  1037. {
  1038.     int dir, x1, y1;
  1039.  
  1040.     if (adj_seen_terrain(x, y, tmpside) && flip_coin()) {
  1041.     init_view_cell(x, y);
  1042.     for_all_directions(dir) {
  1043.         if (point_in_dir(x, y, dir, &x1, &y1)) {
  1044.         init_view_cell(x1, y1);
  1045.         }
  1046.     }
  1047.     }
  1048. }
  1049.  
  1050. static int
  1051. adj_seen_terrain(x, y, side)
  1052. int x, y;
  1053. Side *side;
  1054. {
  1055.     int dir, x1, y1;
  1056.  
  1057.     if (!inside_area(x, y) || side == NULL)
  1058.       return FALSE;
  1059.     for_all_directions(dir) {
  1060.     if (point_in_dir(x, y, dir, &x1, &y1)) {
  1061.         if (terrain_view(side, x1, y1) != UNSEEN)
  1062.           return TRUE;
  1063.     }
  1064.     }
  1065.     return FALSE;
  1066. }
  1067.  
  1068. /* Do ranged initial views from units. */
  1069.  
  1070. void
  1071. init_area_views()
  1072. {
  1073.     int rad, x, y, pop, dir, x1, y1, i = 0;
  1074.     Unit *unit;
  1075.     Side *side, *side2;
  1076.  
  1077.     /* Don't run if nothing exists to look at. */
  1078.     if (!terrain_defined())
  1079.       return;
  1080.     /* Skip if everything already known, side creation got these cases. */
  1081.     if (g_see_all() || g_terrain_seen())
  1082.       return;
  1083.     announce_lengthy_process("Computing ranged and people views");
  1084.     /* Compute the view for each side. */ 
  1085.     for_all_sides(side) {
  1086.     /* Set this so the helper fn has a side to use. */
  1087.     tmpside = side;
  1088.     /* View from our own and other units. */
  1089.     for_all_units(unit) {
  1090.         if (trusted_side(unit->side, side)) {
  1091.         /* The unit always sees itself. */
  1092.         see_exact(side, unit->x, unit->y);
  1093.         /* It may also see things nearby. */
  1094.         rad = u_seen_radius(unit->type);
  1095.         if (rad >= area.maxdim) {
  1096.             /* Special optimization - view the whole area. */
  1097.             for_all_cells(x, y) {
  1098.             init_view_cell(x, y);
  1099.             }
  1100.             /* Note that we're not done; other units may be able to
  1101.                supply more exact views of their vicinities than
  1102.                would init_view_cell from a distant unit. */
  1103.         } else if (rad >= 0) {
  1104.             apply_to_area(unit->x, unit->y, rad, init_view_cell);
  1105.         }
  1106.         }
  1107.     }
  1108.     /* The people see everything in the cells that they are in, plus the
  1109.        normally visible things in adjacent cells. */
  1110.     if (people_sides_defined()) {
  1111.         for_all_interior_cells(x, y) {
  1112.         pop = people_side_at(x, y);
  1113.         side2 = side_n(pop);
  1114.         if (pop != NOBODY && trusted_side(side2, side)) {
  1115.             see_exact(side, x, y);
  1116.             for_all_directions(dir) {
  1117.             if (point_in_dir(x, y, dir, &x1, &y1)) {
  1118.                 init_view_cell(x1, y1);
  1119.             }
  1120.             }
  1121.         }
  1122.         }
  1123.     }
  1124.     if (side->finalradius > 0) {
  1125.         /* (should also view terrain adj to each of these cells, since the
  1126.            viewing represents exploration) */
  1127.         apply_to_ring(side->startx, side->starty,
  1128.               1, side->finalradius - 1,
  1129.               init_view_cell);
  1130.         apply_to_ring(side->startx, side->starty,
  1131.               side->finalradius - 2, side->finalradius + 2,
  1132.               maybe_init_view_cell);
  1133.     }
  1134.     announce_progress((100 * i++) / numsides);
  1135.     }
  1136.     finish_lengthy_process();
  1137. }
  1138.  
  1139. /* Method to give all units and terrain a basic stockpile of supply. */
  1140.  
  1141. int
  1142. make_initial_materials(calls, runs)
  1143. int calls, runs;
  1144. {
  1145.     int m, t, amts[MAXTTYPES], doany, x, y;
  1146.  
  1147.     /* Go over each material and terrain type, looking for nonzero
  1148.        material in terrain possibilities, then alloc and fill in layers
  1149.        as needed. */
  1150.     for_all_material_types(m) {
  1151.     doany = FALSE;
  1152.     for_all_terrain_types(t) {
  1153.         amts[t] = min(tm_storage_x(t, m), tm_initial(t, m));
  1154.         if (amts[t] > 0)
  1155.           doany = TRUE;
  1156.     }
  1157.     if (doany) {
  1158.         allocate_area_material(m);
  1159.         for_all_cells(x, y) {
  1160.         t = terrain_at(x, y);
  1161.         set_material_at(x, y, m, amts[t]);
  1162.         }
  1163.     }
  1164.     }
  1165.     return TRUE;
  1166. }
  1167.  
  1168. /* Give the unit what it is declared to have stockpiled
  1169.    at the start of a game. */
  1170.  
  1171. void
  1172. init_supply(unit)
  1173. Unit *unit;
  1174. {
  1175.     int m, u = unit->type;
  1176.  
  1177.     for_all_material_types(m) {
  1178.     unit->supply[m] = min(um_storage_x(u, m), um_initial(u, m));
  1179.     }
  1180. }
  1181.  
  1182. /* Quicky test needed in a couple places. */
  1183.  
  1184. int
  1185. saved_game()
  1186. {
  1187.     FILE *fp;
  1188.  
  1189.     fp = fopen(saved_game_filename(), "r");
  1190.     if (fp != NULL) {
  1191.     fclose(fp);
  1192.     return TRUE;
  1193.     } else {
  1194.     return FALSE;
  1195.     }
  1196. }
  1197.  
  1198. /* Count all the initial units in each side's balance sheet, but only
  1199.    if all the balance sheets are completely blank. */
  1200.  
  1201. void
  1202. init_side_balance()
  1203. {
  1204.     int u, anything = FALSE;
  1205.     Unit *unit;
  1206.     Side *side;
  1207.  
  1208.     for_all_sides(side) {
  1209.     for_all_unit_types(u) {
  1210.         if (total_gain(side, u) > 0)
  1211.           return;
  1212.     }
  1213.     }
  1214.     for_all_units(unit) {
  1215.     count_gain(unit->side, unit->type, initial_gain);
  1216.     }
  1217. }
  1218.  
  1219. /* This routine does a set of checks to make sure that Xconq's data
  1220.    is in a valid state.  This is particularly important after init,
  1221.    since the combination of files and synthesis methods may have
  1222.    caused some sort of disaster. */
  1223.  
  1224. void
  1225. check_consistency()
  1226. {
  1227.     int x, y;
  1228.  
  1229.     /* If no terrain, make a flat area of all ttype 0. */
  1230.     if (!terrain_defined()) {
  1231.     init_warning("No terrain defined, substituting type 0");
  1232.     allocate_area_terrain();
  1233.     for_all_cells(x, y) {
  1234.         if (inside_area(x, y)) {
  1235.         set_terrain_at(x, y, 0);
  1236.         }
  1237.     }
  1238.     add_edge_terrain();
  1239.     }
  1240.     if (numsides <= 0) {
  1241.     init_error("There are no player sides at all in this game");
  1242.     } else if (numsides < numplayers) {
  1243.     init_warning("Only made %d of the %d sides requested",
  1244.              numsides, numplayers);
  1245.     }
  1246.     /* Need any kind of unit checks? */
  1247. }
  1248.  
  1249. static void
  1250. cache_possible_types()
  1251. {
  1252.     int u, u2, rescan;
  1253.     Unit *unit;
  1254.  
  1255.     u_possible = (short *) xmalloc(numutypes * sizeof(short));
  1256.     for_all_units(unit) {
  1257.     u_possible[unit->type] = TRUE;
  1258.     }
  1259.     rescan = TRUE;
  1260.     while (rescan) {
  1261.     rescan = FALSE;
  1262.     for_all_unit_types(u) {
  1263.         if (u_possible[u]) {
  1264.         for_all_unit_types(u2) {
  1265.             if (uu_acp_to_create(u, u2) > 0
  1266.             && !u_possible[u2]) {
  1267.             u_possible[u2] = TRUE;
  1268.             rescan = TRUE;
  1269.             }
  1270.         }
  1271.         }
  1272.     }
  1273.     }
  1274. }
  1275.  
  1276. /* This does the actual assignment of players to sides, and initializes the
  1277.    side structures appropriately. */
  1278.  
  1279. void
  1280. assign_players_to_sides()
  1281. {
  1282.     int i, numdisplays = 0, numdisplayswanted = 0, numais = 0, n = 0;
  1283.     Side *side;
  1284.     Player *player;
  1285.  
  1286.     announce_lengthy_process("Assigning players to sides");
  1287.     for (i = 0; i < numsides; ++i) {
  1288.     announce_progress((100 * i) / numsides);
  1289.     side = assignments[i].side;
  1290.     player = assignments[i].player;
  1291.     canonicalize_player(player);
  1292.     /* Fix any mistaken advantages. */
  1293.     /* This is a warning here because properly-done interfaces shouldn't
  1294.        allow any mistaken advantages to get this far. */
  1295.     if (player->advantage < side->minadvantage) {
  1296.         init_warning("Requested advantage of %d for %s is too low, will be set to %d",
  1297.              player->advantage, player_desig(player), side->minadvantage);
  1298.         player->advantage = side->minadvantage;
  1299.     }
  1300.     if (player->advantage > side->maxadvantage) {
  1301.         init_warning("Requested advantage of %d for %s is too high, will be set to %d",
  1302.              player->advantage, player_desig(player), side->maxadvantage);
  1303.         player->advantage = side->maxadvantage;
  1304.     }
  1305.     /* Call the interface code to initialize the side's display, if
  1306.        it wants to use one (the interface has to decide). */
  1307.     if (side_wants_display(side)) {
  1308.         ++numdisplayswanted;
  1309.         init_ui(side);
  1310.         if (side_has_display(side)) {
  1311.         ++numdisplays;
  1312.         }
  1313.     }
  1314.     /* Count the desired AIs, for setup below. */
  1315.     if (side_wants_ai(side)) {
  1316.         ++numais;
  1317.     }
  1318.     Dprintf("Assigned %s to %s\n",
  1319.          side_desig(side), player_desig(player));
  1320.     }
  1321.     finish_lengthy_process();
  1322.     if (numdisplays < numdisplayswanted) {
  1323.     if (numdisplays < 1) {
  1324.         init_warning("None of the %d requested displays opened",
  1325.              numdisplayswanted);
  1326.     } else {
  1327.         init_warning("Only %d of %d requested displays opened",
  1328.              numdisplays, numdisplayswanted);
  1329.     }
  1330.     } else if (numdisplays == 0) {
  1331.     init_warning("Need at least one display to run");
  1332.     }
  1333. #ifdef DESIGNERS
  1334.     /* Make each displayed side into a designer if it was requested. */
  1335.     if (allbedesigners) {
  1336.         for_all_sides(side) {
  1337.         if (side_has_display(side)) {
  1338.         become_designer(side);
  1339.         }
  1340.         }
  1341.     }
  1342. #endif /* DESIGNERS */
  1343.     if (numais > 0) {
  1344.     announce_lengthy_process("Setting up AIs");
  1345.     for (i = 0; i < numsides; ++i) {
  1346.         if (numais > 1)
  1347.           announce_progress((100 * n++) / numais);
  1348.         side = assignments[i].side;
  1349.         if (side_wants_ai(side)) {
  1350.         init_ai(side);
  1351.         }
  1352.     }
  1353.     finish_lengthy_process();
  1354.     }
  1355. }
  1356.  
  1357. /* Make sure any debugging I/O routines have allocated their space.
  1358.    Usually routines like side_desig allocate their working space on
  1359.    demand, but if the first demand occurs during a game being saved
  1360.    because allocation fails, then we're in big trouble.  So this
  1361.    routine, which need only be be called when debugging is turned
  1362.    on, calls allocation-needing things in such a way to cause them
  1363.    to allocate their working space. */
  1364.  
  1365. void
  1366. prealloc_debug()
  1367. {
  1368.     side_desig(NULL);
  1369.     player_desig(NULL);
  1370.     unit_desig(NULL);
  1371.     shortest_unique_name(0);
  1372. }
  1373.  
  1374. /* Return the program version. */
  1375.  
  1376. char *
  1377. version_string()
  1378. {
  1379.     return VERSION;
  1380. }
  1381.  
  1382. /* Return the copyright notice. */
  1383.  
  1384. char *
  1385. copyright_string()
  1386. {
  1387.     return COPYRIGHT;
  1388. }
  1389.  
  1390. /* Return the license string. */
  1391.  
  1392. char *
  1393. license_string()
  1394. {
  1395.     return "\
  1396. Xconq is free software and you are welcome to distribute copies of it\n\
  1397. under certain conditions; type \"o copying\" to see the conditions.\n\
  1398. There is absolutely no warranty for Xconq; type \"o warranty\" for details.\n\
  1399. ";
  1400. }
  1401.  
  1402. /* This comment is a fake reference to K_NO_X, which is a keyword used
  1403.    to clear the subtype-x property of terrain, but is not actually
  1404.    mentioned in the code - besides here anyway. :-) */
  1405.