<HTML> <HEAD> <!-- This HTML file has been created by texi2html 1.39 from ./hacking.texi on 12 June 2005 --> <TITLE>Hacking Xconq - Main Program</TITLE> </HEAD> <BODY> Go to the <A HREF="hacking_1.html">first</A>, <A HREF="hacking_11.html">previous</A>, <A HREF="hacking_13.html">next</A>, <A HREF="hacking_35.html">last</A> section, <A HREF="hacking_toc.html">table of contents</A>. <HR> <H2><A NAME="SEC12" HREF="hacking_toc.html#SEC12">Main Program</A></H2> <P> The interface provides <CODE>main()</CODE> for <I>Xconq</I>; this allows maximum flexibility in adapting to different environments. In a sense, the kernel is a large library that the interface calls to do game-related operations. </P> <P> There is a standard set of calls that need to be made during initialization. The set changes from time to time, so the following extract from <TT>`skelconq'</TT> should not be taken as definitive: <PRE> init_library_path(NULL); clear_game_modules(); init_data_structures(); parse_command_line(argc, argv, general_options); load_all_modules(); check_game_validity(); parse_command_line(argc, argv, variant_options); set_variants_from_options(); parse_command_line(argc, argv, player_options); set_players_from_options(); parse_command_line(argc, argv, leftover_options); make_trial_assignments(); calculate_globals(); run_synth_methods(); final_init(); assign_players_to_sides(); init_displays(); init_signal_handlers(); run_game(0); </PRE> <P> Note that this sequence is only straight-through for a simple command line option program; if you have one or more game setup dialogs, then you choose which to call based on how the players have progressed through the dialogs. The decision points more-or-less correspond to the different <CODE>parse_command_line</CODE> calls in the example. You may also need to interleave some interface-specific calls; for instance, if you want to display side emblems in a player/side selection dialog, then you will need to arrange for the emblem images to be loaded and displayable, rather than doing it as part of opening displays. </P> <P> Once a game is underway, the interface is basically self-contained, needing only to call <CODE>run_game</CODE> periodically to keep the game moving along. <CODE>run_game</CODE> takes one argument which can be -1, 0, or 1. If 1, then one unit gets to do one action, then the routine returns. If 0, the calculations are gone through, but no units can act. If -1, then all possible units will move before <CODE>run_game</CODE> returns. This last case is not recommended for interactive programs, since moving all units in a large game may take a very long time; several minutes sometimes, and <CODE>run_game</CODE> may not necessarily call back to the interface very often. </P> <HR> Go to the <A HREF="hacking_1.html">first</A>, <A HREF="hacking_11.html">previous</A>, <A HREF="hacking_13.html">next</A>, <A HREF="hacking_35.html">last</A> section, <A HREF="hacking_toc.html">table of contents</A>. </BODY> </HTML>