#include <gtk/gtk.h>
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
#include <main.h>
#include <savegame_fe.h>
#include <budget.h>
#include <logging.h>
#include <locking.h>
#include <ui.h>
#include <handler.h>
#include <drawing.h>
#include <globals.h>
#include <build.h>
#include <simulation.h>
#include <disaster.h>
#include <compilerpragmas.h>
#include <nix_utils.h>
#include <simulation-ui.h>
#include <zonemon.h>
Go to the source code of this file.
Data Structures | |
struct | image_pms |
image pixmaps More... | |
struct | main_window |
the main window's contents More... | |
Defines | |
#define | PATHSEARCH ".:./graphic:./graphic/icons:../graphic" |
path to search for graphics | |
Functions | |
void | SetUpMainWindow (void) |
set up and configure the main window. | |
gint | mainloop_callback (gpointer data) |
time ticker that loops every second | |
void | QuitGame (void) |
terminate the game. | |
void | SetSpeed (gpointer data, guint action, GtkWidget *w) |
set the game speed | |
void | cleanupPixmaps (void) |
clean up the pixmaps | |
void | ResetViewable (void) |
set the tile size | |
void | forceRedistribute (void) |
force a redistribution next iteration | |
int | main (int argc, char **argv) |
the main routine | |
gint | toolbox_callback (GtkWidget *widget, gpointer data) |
set the item that will be build upon clicking on the play surface | |
void | scrollbar (GtkAdjustment *adj) |
slide the scrollbar | |
void | ResizeCheck (int width, int height) |
check the size of the screen. | |
void | check_configure (GtkContainer *widget, GdkEventConfigure *event, gpointer data) |
the configure event handler for the play area. | |
gint | delete_event (GtkWidget *widget, GdkEvent *event, gpointer data) |
when the close button is clicked, this event is called | |
gint | drawing_exposed_callback (GtkWidget *widget, GdkEventExpose *event, gpointer data) |
the drawing area is exposed, and needs to be painted. | |
gint | drawing_realized_callback (GtkWidget *widget, GdkEvent *event, gpointer data) |
Realize the drawing area once it is created. | |
gint | button_press_event (GtkWidget *widget, GdkEventButton *event) |
someone clicked on the play area. | |
gint | motion_notify_event (GtkWidget *widget, GdkEventMotion *event) |
somethings moved | |
GtkWidget * | setupToolBox (void) |
set up the toolbox | |
GtkAccelGroup * | createMenu (GtkWidget *main_box) |
create the keyboard and menu accelerator groups | |
gboolean | hoveringDrawing (GtkWidget *widget, GdkEventMotion *event, gpointer data) |
hovering over the drawing area | |
void | UIInitGraphic (void) |
initialize the graphics | |
void | UIDisplayError1 (char *error) |
Display and error dialog with one parameter. | |
void | UIProblemNotify (problem_t problem) |
notify that theres a problem in the city. | |
void | UIInitDrawing (void) |
Initialize the drawing area. | |
void | UIFinishDrawing (void) |
finish up using the drawing area | |
void | UIPostLoadGame (void) |
UI post load game handler. | |
void | UIUnlockScreen (void) |
unlock the screen, allow any paused repainting to happen | |
void | UILockScreen (void) |
lock the screen, pause any painting operations to happen | |
void | UIDrawBorder (void) |
void | UIDrawCredits (void) |
set the labels for the credits and time | |
void | UIDrawDate (void) |
update/draw the date on screen | |
void | UIDrawLoc (void) |
Draw the Location on screen. | |
void | UIDrawPop (void) |
draw the population | |
void | UIDrawSpeed (void) |
Draw the speed/update the seed icon on screen. | |
void | UIDrawBuildIcon (void) |
Draw the build icon on the display. | |
void | UIUpdateBuildIcon (void) |
void | UIGotoForm (Int16 n) |
void | UICheckMoney (void) |
Check if we've got dosh to do what we're asking to do. | |
void | UIScrollDisplay (dirType direction) |
scroll the map in the appropriate direction | |
void | _UIDrawRect (Int16 nTop, Int16 nLeft, Int16 nHeight, Int16 nWidth) |
in theory draw a rectangle. | |
void | UIPaintField (UInt16 xpos, UInt16 ypos, welem_t nGraphic) |
draw a field | |
void | UIPaintSpecialObject (UInt16 xpos, UInt16 ypos, Int8 i) |
Draw a special object. | |
void | UIPaintSpecialUnit (UInt16 xpos, UInt16 ypos, Int8 i) |
draw a special unit on the screen | |
void | UIDrawMapZone (Int16 xpos, Int16 ypos, welem_t nGraphic, GdkDrawable *drawable) |
draw a field for the map | |
void | UIDrawMapSpecialObject (Int16 xpos, Int16 ypos, Int16 i, GdkDrawable *drawable) |
draw a special object for the map | |
void | UIDrawMapSpecialUnit (Int16 xpos, Int16 ypos, Int16 i, GdkDrawable *drawable) |
draw a special unit on the map | |
void | UIPaintCursor (UInt16 xpos, UInt16 ypos) |
draw a cursor at the location specified | |
void | DrawOverlay (UInt16 xpos, UInt16 ypos, welem_t offset) |
draw an overlay icon on the screen | |
void | UIPaintPowerLoss (UInt16 xpos, UInt16 ypos) |
Draw a power loss overlay on the screen at the specified location. | |
void | UIPaintWaterLoss (UInt16 xpos, UInt16 ypos) |
Draw a water loss overlay on the screen at the specified location. | |
BuildCode | UIGetSelectedBuildItem (void) |
get the selected item to build | |
void | clearPaintedFlag (void) |
clear the painted flag | |
void | setPaintedFlag (void) |
set the painted flag | |
int | getPaintedFlag (void) |
test painted flag | |
void | UIDrawPlayArea (void) |
void | UIMapResize (void) |
map being resized, do UI related elements | |
Int8 | UIClipped (UInt16 xpos, UInt16 ypos) |
check if the map location is being clipped by the game | |
void | LockZone (lockZone zone) |
lock the zone specified for writing | |
void | UnlockZone (lockZone zone) |
unlock the zone specified. don't write to it anymore | |
void | ReleaseZone (lockZone zone) |
release the memory allocated to this zone | |
UInt32 | GetRandomNumber (UInt32 max) |
get a random number between 0 and max | |
void | MapHasJumped (void) |
the map has jumped to another location | |
Variables | |
main_window | mw |
the main window's contents | |
char * | exec_dir |
the execution directory of the program | |
const GtkItemFactoryEntry | menu_items [] |
the menu items for the main application | |
UInt8 | selectedBuildItem = 0 |
handle to the bitmap masks for rendering the units | |
image_pms | image_pixmaps [] |
image pixmaps | |
int | painted_flag |
painted flag - for play area back-buffer |
This file contains all the major routines to perform the simulation in the GTK environment.
Definition in file main.c.
|
someone clicked on the play area. The play area has a button pressed upon it. As a consequence we need to either build something or bulldoze the area.
Definition at line 392 of file main.c. References Build_Bulldoze(), and BuildSomething(). Referenced by SetUpMainWindow(). |
|
the configure event handler for the play area. Resizes the playing area elements to ensure that the play area is displayed with the correct size on screen.
Definition at line 305 of file main.c. References ResizeCheck(). Referenced by SetUpMainWindow(). |
|
create the keyboard and menu accelerator groups
Definition at line 540 of file main.c. References menu_items. Referenced by SetUpMainWindow(). |
|
when the close button is clicked, this event is called MAkes the main event loop terminate.
Definition at line 323 of file main.c. Referenced by SetUpMainWindow(). |
|
the drawing area is exposed, and needs to be painted. This is an expose event for the drawing area to cause the screen to be repainted. Redraws all the fields that are on the screen.
Definition at line 342 of file main.c. References mw, and main_window::p_play. Referenced by SetUpMainWindow(). |
|
Realize the drawing area once it is created. This call is issued once the drawing area is initially created. It allows us to create a new game and make sure the screen is the correct size.
Definition at line 376 of file main.c. Referenced by SetUpMainWindow(). |
|
draw an overlay icon on the screen
Definition at line 1138 of file main.c. References HORIZONTAL_TILESIZE, mw, main_window::p_play, main_window::p_zones, main_window::p_zones_m, UInt16, and welem_t. Referenced by UIPaintPowerLoss(), and UIPaintWaterLoss(). |
|
test painted flag
|
|
get a random number between 0 and max
Definition at line 1274 of file main.c. References UInt32. Referenced by CreateDragon(), CreateForest(), CreateForests(), CreateFullRiver(), CreateMeteor(), CreateMonster(), DoCommitmentNasties(), DoNastyStuffTo(), DoRandomDisaster(), DoSpecificDisaster(), GetRandomZone(), MeteorDisaster(), MonsterCheckSurrounded(), MoveAllObjects(), and UpdateDisasters(). |
|
hovering over the drawing area
Definition at line 565 of file main.c. References hoverUpdate(). Referenced by SetUpMainWindow(). |
|
lock the zone specified for writing
Definition at line 1253 of file main.c. References lockZone. Referenced by Build_Bulldoze(), Build_Defence(), Build_Generic(), Build_Generic4(), Build_PowerLine(), Build_Rail(), Build_Road(), Build_WaterPipe(), BuildSomething(), BurnField(), CreateDragon(), CreateForest(), CreateFullRiver(), CreateMeteor(), CreateMonster(), CreateWaste(), DoDistribute(), DoNastyStuffTo(), DoRandomDisaster(), DowngradeZone(), FindScoreForZones(), GetRandomZone(), GetZoneScore(), hoverUpdate(), LoadGameByIndex(), MoveAllObjects(), MoveCursor(), querySetup(), ReleaseZone(), RenderMaps(), ResizeWorld(), SaveGameByIndex(), setMapSize(), UIPaintPlayArea(), UIScrollDisplay(), UpdateDisasters(), and UpdateVolatiles(). |
|
the main routine Sets up the windows and starts the simulation
Definition at line 114 of file main.c. References cleanupPixmaps(), ConfigureNewGame(), exec_dir, InitGameStruct(), main(), mainloop_callback(), PCityMain(), PurgeWorld(), ResetViewable(), and SetUpMainWindow(). Referenced by main(). |
|
time ticker that loops every second
Definition at line 193 of file main.c. References main_window::drawing, getMonthsElapsed, MoveAllObjects(), mw, Sim_DoPhase(), SIM_GAME_LOOP_DISASTER, SPEED_PAUSED, UIUpdateBudget(), and UpdateDisasters(). Referenced by main(). |
|
the map has jumped to another location Ensure that the scroll bars are moved correctly. Definition at line 1284 of file main.c. References main_window::drawing, mw, main_window::sc_hor, and main_window::sc_vert. Referenced by doOpen(), DoSpecificDisaster(), and ImportOneFromGame(). |
|
somethings moved Ooooooooo.... I have no clue Definition at line 414 of file main.c. References Build_Bulldoze(), and BuildSomething(). Referenced by SetUpMainWindow(). |
|
terminate the game. Invoked when the quit option is selected from the menu |
|
release the memory allocated to this zone
Definition at line 1265 of file main.c. References lockZone, and lz_world. Referenced by PurgeWorld(). |
|
set the tile size We set the tile size (16 pels). We reserve 2 tiles (one at the top, one at the bottom) for use with status information. Definition at line 241 of file main.c. References UInt16. Referenced by LoadGameByIndex(), and main(). |
|
check the size of the screen. intended to allow the play area to expand and contract; this code is used by the initial sizing algorithm, as well as the resize handler.
Definition at line 271 of file main.c. References getMapHeight, getMapWidth, mw, main_window::sc_hor, and main_window::sc_vert. Referenced by check_configure(). |
|
slide the scrollbar Moves the display to the appropriate location.
Definition at line 255 of file main.c. References Goto(), mw, main_window::sc_hor, and main_window::sc_vert. Referenced by SetUpMainWindow(). |
|
set the game speed
|
|
set up and configure the main window. Creates the main window. Creates all the elements of the main window including the toolbar (!grrrrr) Definition at line 580 of file main.c. References button_press_event(), check_configure(), createMenu(), delete_event(), main_window::drawing, drawing_exposed_callback(), drawing_realized_callback(), hoveringDrawing(), main_window::hscroll, main_window::l_credits, main_window::l_location, main_window::l_pop, main_window::l_time, motion_notify_event(), mw, main_window::sc_hor, main_window::sc_vert, scrollbar(), setupToolBox(), main_window::vscroll, and main_window::window. Referenced by main(). |
|
set up the toolbox
Definition at line 450 of file main.c. References PATHSEARCH, searchForFile(), and toolbox_callback(). Referenced by SetUpMainWindow(). |
|
set the item that will be build upon clicking on the play surface
Definition at line 233 of file main.c. References selectedBuildItem. Referenced by setupToolBox(). |
|
Check if we've got dosh to do what we're asking to do. unused Definition at line 974 of file main.c. Referenced by Sim_DoPhase(). |
|
check if the map location is being clipped by the game
Definition at line 1246 of file main.c. References UInt16. Referenced by DrawFieldWithoutInit(), PaintLossIcon(), UIPaintField(), UIPaintSpecialObject(), and UIPaintSpecialUnit(). |
|
Display and error dialog with one parameter.
Definition at line 755 of file main.c. References mw, and main_window::window. Referenced by BuildSomething(), and UIProblemNotify(). |
|
unused |
|
Draw the build icon on the display.
|
|
draw a special object for the map
Definition at line 1089 of file main.c. References Int16, mw, and main_window::p_mapspecials. |
|
draw a special unit on the map
Definition at line 1107 of file main.c. References Int16, mw, and main_window::p_units. |
|
draw a field for the map
Definition at line 1072 of file main.c. References HORIZONTAL_TILESIZE, Int16, mw, main_window::p_mapzones, and welem_t. Referenced by UIPaintMapField(). |
|
Definition at line 1211 of file main.c. References DrawFieldWithoutInit(), main_window::drawing, getMapHeight, getMapWidth, getWorldFlags(), Int16, mw, PAINTEDBIT, and WORLDPOS. |
|
draw the population Actually simply set the population label to the appropriate value. Definition at line 931 of file main.c. References getPopulation(), main_window::l_pop, and mw. |
|
Draw the speed/update the seed icon on screen.
|
|
finish up using the drawing area unused Definition at line 858 of file main.c. Referenced by DrawCross(), DrawField(), performPaintDisplay(), and UIScrollDisplay(). |
|
get the selected item to build
Definition at line 1174 of file main.c. Referenced by BuildSomething(). |
|
unused Definition at line 967 of file main.c. References Int16. |
|
Initialize the drawing area. unused Definition at line 852 of file main.c. Referenced by DrawCross(), DrawField(), performPaintDisplay(), and UIScrollDisplay(). |
|
initialize the graphics
Definition at line 714 of file main.c. References image_pms::filename, image_pixmaps, image_pms::mask, mw, PATHSEARCH, image_pms::pm, searchForFile(), and main_window::window. Referenced by InitGraphic(). |
|
lock the screen, pause any painting operations to happen unused Definition at line 876 of file main.c. Referenced by CreateMeteor(). |
|
map being resized, do UI related elements The resizing of the map corresponds to recreating the backing map area as well as the backing play area. Definition at line 1235 of file main.c. References clearPaintedFlag(), getMapHeight, getMapWidth, mw, main_window::p_play, and resizeMap(). Referenced by PostLoadGame(), and setMapSize(). |
|
draw a cursor at the location specified
Definition at line 1125 of file main.c. References UInt16. Referenced by DrawFieldWithoutInit(), and UIScrollDisplay(). |
|
draw a field
Definition at line 1003 of file main.c. References main_window::drawing, HORIZONTAL_TILESIZE, mw, main_window::p_play, main_window::p_zones, UInt16, and welem_t. Referenced by DrawFieldWithoutInit(). |
|
Draw a power loss overlay on the screen at the specified location. The field has already been determined to not have power Definition at line 1162 of file main.c. References DrawOverlay(), and UInt16. Referenced by DrawFieldWithoutInit(). |
|
Draw a special object.
Definition at line 1022 of file main.c. References main_window::drawing, Int8, mw, main_window::p_monsters, main_window::p_monsters_m, main_window::p_play, and UInt16. Referenced by DrawFieldWithoutInit(). |
|
draw a special unit on the screen
Definition at line 1047 of file main.c. References main_window::drawing, Int8, mw, main_window::p_play, main_window::p_units, main_window::p_units_m, and UInt16. Referenced by DrawFieldWithoutInit(). |
|
Draw a water loss overlay on the screen at the specified location. The Field has already been determined to not have water. Definition at line 1168 of file main.c. References DrawOverlay(), and UInt16. Referenced by DrawFieldWithoutInit(). |
|
UI post load game handler. unused Definition at line 864 of file main.c. Referenced by PostLoadGame(). |
|
notify that theres a problem in the city.
Definition at line 801 of file main.c. References peFineOnMoney, peFineOnPower, peFineOnWater, peLowOnMoney, peLowOnPower, peLowOnWater, peOutOfMoney, peOutOfPower, peOutOfWater, problem_t, and UIDisplayError1(). Referenced by Build_Bulldoze(), Build_Generic(), Build_Generic4(), Build_PowerLine(), Build_Rail(), Build_Road(), Build_WaterPipe(), DoDistribute(), and UICheckMoney(). |
|
scroll the map in the appropriate direction
Definition at line 985 of file main.c. References dirType, main_window::drawing, mw, and RedrawAllFields(). Referenced by ScrollDisplay(). |
|
unused |
|
unlock the zone specified. don't write to it anymore
Definition at line 1259 of file main.c. References lockZone. Referenced by Build_Bulldoze(), Build_Defence(), Build_Generic(), Build_Generic4(), Build_PowerLine(), Build_Rail(), Build_Road(), Build_WaterPipe(), BuildSomething(), BurnField(), CreateDragon(), CreateForest(), CreateFullRiver(), CreateMeteor(), CreateMonster(), CreateWaste(), DoDistribute(), DoNastyStuffTo(), DoRandomDisaster(), DowngradeZone(), FindScoreForZones(), GetRandomZone(), GetZoneScore(), hoverUpdate(), LoadGameByIndex(), MoveAllObjects(), MoveCursor(), querySetup(), RenderMaps(), ResizeWorld(), SaveGameByIndex(), setMapSize(), UIPaintPlayArea(), UIScrollDisplay(), UpdateDisasters(), and UpdateVolatiles(). |
|
Initial value: { { "/_File", NULL, NULL, 0, "<Branch>", 0 }, { "/File/_New", "<control>N", newgame_handler, 0, NULL, 0 }, { "/File/_Open", "<control>O", opengame_handler, 0, NULL, NULL }, { "/File/_Save", "<control>S", savegame_handler, 0, NULL, 0 }, { "/File/Save _As", NULL, savegameas_handler, 0, NULL, 0 }, { "/File/sep1", NULL, NULL, 0, "<Separator>", 0 }, { "/File/E_xit", "<alt>F4", QuitGame, 0, NULL, 0 }, { "/_View", NULL, NULL, 0, "<Branch>", 0 }, { "/View/_Budget", "<control>B", ViewBudget, 0, NULL, 0 }, { "/View/_Map", "<control>M", showMap, 0, NULL, 0 }, { "/View/_Hover", NULL, hoverShow, 0, NULL, 0 }, { "/_Speed", NULL, NULL, 0, "<Branch>", 0 }, { "/Speed/_Pause", "<control>0", SetSpeed, 1 + SPEED_PAUSED, NULL, NULL }, { "/Speed/sep1", NULL, NULL, 0, "<Separator>", 0 }, { "/Speed/_Slow", "<control>1", SetSpeed, 1 + SPEED_SLOW, NULL, NULL }, { "/Speed/_Medium", "<control>2", SetSpeed, 1 + SPEED_MEDIUM, NULL, NULL }, { "/Speed/_Fast", "<control>3", SetSpeed, 1 + SPEED_FAST, NULL, NULL }, { "/Speed/_Turbo", "<control>4", SetSpeed, 1 + SPEED_TURBO, NULL, NULL }, { "/S_imulation", NULL, NULL, 0, "<Branch>", 0 }, { "/Simulation/_Redistribute", NULL, forceRedistribute, 0, NULL, NULL } }
Definition at line 78 of file main.c. Referenced by createMenu(). |