Main Page   Data Structures   File List   Data Fields   Globals   Related Pages  

palm/simcity.c File Reference

the main simulation code routines More...

#include <PalmOS.h>
#include <StringMgr.h>
#include <KeyMgr.h>
#include <StdIOPalm.h>
#include <simcity.h>
#include <savegame.h>
#include <savegame_be.h>
#include <options.h>
#include <map.h>
#include <budget.h>
#include <zakdef.h>
#include <ui.h>
#include <drawing.h>
#include <build.h>
#include <query.h>
#include <handler.h>
#include <globals.h>
#include <simulation.h>
#include <disaster.h>
#include <resCompat.h>
#include <palmutils.h>
#include <simcity_resconsts.h>
#include <mem_compat.h>
#include <minimap.h>
#include <beam.h>
#include <logging.h>
#include <locking.h>

Go to the source code of this file.

Data Structures

struct  _bmphandles
 Handles and resourceID's of the bitmaps. More...

struct  _silkKeys
 structure for mapping the silk keys to 'button keys' More...

struct  problemtable
 table containing the problem_table input/output function More...

struct  StatusPositions
 the status positions More...


Defines

#define posAt(x)   &(lrpositions[(x)])
 get low resolution positions

#define MAXLOC   (sizeof (lrpositions) / sizeof (lrpositions[0]))
 maximum size of positions array

#define MAX_SPEED   (sizeof (speedslist) / sizeof (speedslist[0]))
 maximum speed


Functions

void buildSilkList (void)
 find the calculator button on the screen

Int16 vkDoEvent (UInt16 key)
 process a virtual key press

Err RomVersionCompatible (UInt32 requiredVersion, UInt16 launchFlags)
 is the ROM on this machine compatible

void cycleSpeed (void)
 cycle up to the next speed

void CheckTextClick (Coord x, Coord y)
 Perform an action based on the location on screen that was clicked.

Int16 doButtonEvent (ButtonEvent key)
 Do the command against the key passed.

Int16 speedOffset (void)
 get the offset of the speed into the speedslist array

void performPaintDisplay (void)
 actually perform all the painting This will perform all the painting that has been asked for on the display. It allows us to pool all the painting in one point; which allows for more consistent painting of the display; rather than mandating the painting at a point that would make it inefficient.

void UIPostLoadGame (void)
 UI post load game handler.

void UIGotoForm (Int16 n)
BuildCode UIGetSelectedBuildItem (void)
 get the selected item to build

void UIInitGraphic (void)
 initialize the graphics

void ClearLowOutPowerFlags (void)
 clear the low and out of power flags

void ClearLowOutWaterFlags (void)
 clear the low and out water flags

void ClearLowOutMoneyFlags (void)
 clear the low and out of money flags

void UIProblemNotify (problem_t problem)
 notify that theres a problem in the city.

void UIDisplayError1 (char *message)
 Display and error dialog with one parameter.

void UIInitDrawing (void)
 Initialize the drawing area.

void UIFinishDrawing (void)
 finish up using the drawing area

void UILockScreen (void)
 lock the screen, pause any painting operations to happen

void UIUnlockScreen (void)
 unlock the screen, allow any paused repainting to happen

void _UIDrawRect (Int16 nTop, Int16 nLeft, Int16 nHeight, Int16 nWidth)
 in theory draw a rectangle.

void UISetUpGraphic (void)
 Setup the graphics.

void UIPaintCursor (UInt16 xpos, UInt16 ypos)
 draw a cursor at the location specified

void PaintLossIcon (UInt16 xpos, UInt16 ypos, welem_t elem)
 Draw a generic loss icon.

void UIPaintWaterLoss (UInt16 xpos, UInt16 ypos)
 Draw a water loss overlay on the screen at the specified location.

void UIPaintPowerLoss (UInt16 xpos, UInt16 ypos)
 Draw a power loss overlay on the screen at the specified location.

void UIPaintSpecialUnit (UInt16 xpos, UInt16 ypos, Int8 i)
 draw a special unit on the screen

void UIPaintSpecialObject (UInt16 xpos, UInt16 ypos, Int8 i)
 Draw a special object.

void UIPaintField (UInt16 xpos, UInt16 ypos, welem_t nGraphic)
 draw a field

void UIPaintPlayArea (void)
 draw the play area

void UIPaintDesires (void)
 Paint the desires on the display.

void UIScrollDisplay (dirType direction)
 scroll the map in the appropriate direction

UInt32 GetRandomNumber (UInt32 max)
 get a random number between 0 and max

void DrawItem (loc_screen location, char *text)
 Draw a status item at the position requested.

Int16 UICheckOnClick (Coord x, Coord y)
 Check a click in the display.

void UIPaintDate (void)
 Draw the date on screen.

void UIPaintCredits (void)
 Draw the amount of credits on screen.

void UIPaintLocation (void)
 Draw the map position on screen.

void UIPaintBuildIcon (void)
 Update the build icon on screen.

Int8 UIClipped (UInt16 xpos, UInt16 ypos)
 check if the map location is being clipped by the game

void UIPaintSpeed (void)
 Draw the speed icon on screen.

void UIPaintPopulation (void)
 Draw the population on screen.

void UICheckMoney (void)
 Check if we've got dosh to do what we're asking to do.

void MapHasJumped (void)
 the map has jumped to another location

Int16 HardButtonEvent (ButtonKey key)
 process a hard button being pressed


Variables

WinHandle winZones
 the on screen zones

WinHandle winMonsters
 the Monsters

WinHandle winUnits
 The defensive units.

WinHandle winSpeeds
 the offscreen window containing the speed images

const struct _bmphandles handles []
 Handles and resourceID's of the bitmaps.

problemtable problem_table []
 table containing the problem_table input/output function

UInt8didLock = NULL
 handle for checking in the winscfeenunlock function The WinScreenLock is 'optional' depending on how much memory you have. the call may or may not succeed. by using these two APIs we can get faster, flickerless allscreen updating

UInt8 lockCalls = 0
RectangleType shapes []
 the default shape/size of the various locations

const struct StatusPositions lrpositions []
 the positions of the items on screen - low resolution

UInt8 speedslist []
 list of speeds in game

_silkKeys silky []
 structure for mapping the silk keys to 'button keys'


Detailed Description

the main simulation code routines

This file has all the routines to deal with the startup and general main loop-executionness of the program.

Definition in file simcity.c.


Define Documentation

#define BUILD_STATEBITACCESSOR BIT,
CLEARER,
SETTER,
TESTER,
VISIBILITY   
 

Value:

VISIBILITY void \
CLEARER(void) \
{ \
        __state &= ~((UInt16)1<<(BIT)); \
} \
VISIBILITY void \
SETTER(void) \
{ \
        __state |= ((UInt16)1<<(BIT)); \
} \
VISIBILITY UInt16 \
TESTER(void) \
{ \
        return (__state & ((UInt16)1<<(BIT))); \
}

Definition at line 1236 of file simcity.c.


Function Documentation

void buildSilkList void    [static]
 

find the calculator button on the screen

The calculator button can be a favorites button on the Zire. The problem is that the Zire uses a different code on PalmOS 4 than on PalmOS 5 for the key, making it not work.

Definition at line 2505 of file simcity.c.

References isZireOld(), silky, UInt16, and _silkKeys::vChar.

void CheckTextClick Coord    x,
Coord    y
[static]
 

Perform an action based on the location on screen that was clicked.

Parameters:
x  the x location
y  the y location

Definition at line 2046 of file simcity.c.

References doButtonEvent(), GETMINIMAPVISIBLE, and UICheckOnClick().

void cycleSpeed void    [static]
 

cycle up to the next speed

This will loop back around to paused when you exceed turbo

Definition at line 2365 of file simcity.c.

References MAX_SPEED, speedslist, and UInt16.

Int16 doButtonEvent ButtonEvent    event [static]
 

Do the command against the key passed.

Parameters:
event  the event that is being triggered
Returns:
1 if the event was dealt with, 0 otherwise.

Definition at line 2382 of file simcity.c.

References addGraphicUpdate(), dtDown, dtLeft, dtRight, dtUp, gu_location, and ScrollDisplay().

Referenced by CheckTextClick(), and HardButtonEvent().

void DrawItem loc_screen    location,
char *    text
[static]
 

Draw a status item at the position requested.

Parameters:
location  the item to print
text  the text to display

Definition at line 1971 of file simcity.c.

References StatusPositions::extents, Int16, StatusPositions::offset, StatusPositions::point, posAt, and shapes.

Referenced by UIPaintCredits(), UIPaintDate(), UIPaintLocation(), and UIPaintPopulation().

UInt32 GetRandomNumber UInt32    max
 

get a random number between 0 and max

Parameters:
max  the maximum limit of the value to obtain
Returns:
the random number

Definition at line 1868 of file simcity.c.

References UInt32.

Int16 HardButtonEvent ButtonKey    key [static]
 

process a hard button being pressed

Parameters:
key  the key what was received
Returns:
the code from performing the button event

Definition at line 2454 of file simcity.c.

References ButtonKey, and doButtonEvent().

Referenced by vkDoEvent().

void MapHasJumped void   
 

the map has jumped to another location

Ensure that the scroll bars are moved correctly.

Definition at line 2273 of file simcity.c.

void PaintLossIcon UInt16    xpos,
UInt16    ypos,
welem_t    elem
[static]
 

Draw a generic loss icon.

It is obtained from the zones bitmap. The location in the zones bitmap is stated by the tilex and tiley values. This specifies the overlay. The icon itself is tile pixels before this.

Parameters:
xpos  the x position on the area to paint
ypos  the y position on the area to paint
elem  the element to use for the loss icon

Definition at line 1560 of file simcity.c.

References HORIZONTAL_TILESIZE, UIClipped(), UInt16, welem_t, and winZones.

Referenced by UIPaintPowerLoss(), and UIPaintWaterLoss().

Err RomVersionCompatible UInt32    requiredVersion,
UInt16    launchFlags
[static]
 

is the ROM on this machine compatible

Parameters:
requiredVersion  the asked for version (3.5)
launchFlags  flags for launching
Returns:
true if OK, false otherwise
Checks if the rom is compatible so we can pay the game. It may be partially compatible (3.1+) in which caase flag that fact Also permit/deny direct structure access depending on the version.

Definition at line 2288 of file simcity.c.

References UInt16, and UInt32.

Int16 speedOffset void    [static]
 

get the offset of the speed into the speedslist array

This is used to calculate the index into the speed bitmap for display purposes

Returns:
the index into the array, or 0 as a default

Definition at line 2349 of file simcity.c.

References MAX_SPEED, speedslist, and UInt16.

Referenced by UIPaintSpeed().

void UICheckMoney void   
 

Check if we've got dosh to do what we're asking to do.

If we're nearly broke show us a warning dialog. If we're broke then show us a we're broke dialog. Only show them once per load cycle.

Definition at line 2263 of file simcity.c.

References peLowOnMoney, peOutOfMoney, and UIProblemNotify().

Int16 UICheckOnClick Coord    x,
Coord    y
[static]
 

Check a click in the display.

Parameters:
x  the x location
y  the y location
Returns:
the item, or -1 if not one of the items.
See if it's one of the status locations. If it is then return it.

Definition at line 2026 of file simcity.c.

References MAXLOC, shapes, and UInt16.

Referenced by CheckTextClick().

Int8 UIClipped UInt16    xpos,
UInt16    ypos
 

check if the map location is being clipped by the game

Parameters:
xpos  the x position on the map
ypos  the y position on the map
Returns:
true if the point on the map is clipped, and therefore not visible

Definition at line 2175 of file simcity.c.

References UInt16.

void UIDisplayError1 char *    error
 

Display and error dialog with one parameter.

Parameters:
error  the message to use in the dialog

Definition at line 1423 of file simcity.c.

void UIFinishDrawing void   
 

finish up using the drawing area

unused

Definition at line 1440 of file simcity.c.

BuildCode UIGetSelectedBuildItem void   
 

get the selected item to build

Returns:
the item that is selected.

Definition at line 1202 of file simcity.c.

void UIGotoForm Int16    n
 

unused

Definition at line 929 of file simcity.c.

References Int16, and UInt16.

void UIInitDrawing void   
 

Initialize the drawing area.

unused

Definition at line 1432 of file simcity.c.

void UIInitGraphic void   
 

initialize the graphics

Todo:
fix this routine.

Definition at line 1211 of file simcity.c.

void UILockScreen void   
 

lock the screen, pause any painting operations to happen

\Try to lock the screen from updates.

This allows bulk updates to the screen without repainting until unlocked.

Definition at line 1460 of file simcity.c.

References didLock, and lockCalls.

void UIPaintCursor UInt16    xpos,
UInt16    ypos
 

draw a cursor at the location specified

Parameters:
xpos  the xposition
ypos  the y position

Definition at line 1544 of file simcity.c.

References UInt16.

void UIPaintField UInt16    xpos,
UInt16    ypos,
welem_t    nGraphic
 

draw a field

Parameters:
xpos  the horizontal position
ypos  the vertical position
nGraphic  the item to paint

Definition at line 1683 of file simcity.c.

References HORIZONTAL_TILESIZE, UIClipped(), UInt16, welem_t, and winZones.

void UIPaintPowerLoss UInt16    xpos,
UInt16    ypos
 

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 1607 of file simcity.c.

References PaintLossIcon(), and UInt16.

void UIPaintSpecialObject UInt16    xpos,
UInt16    ypos,
Int8    i
 

Draw a special object.

Parameters:
xpos  the horizontal position
ypos  the vertical position
i  the item to draw

Definition at line 1651 of file simcity.c.

References Int8, UIClipped(), UInt16, and winMonsters.

void UIPaintSpecialUnit UInt16    xpos,
UInt16    ypos,
Int8    i
 

draw a special unit on the screen

Parameters:
i  the unit number being painted (index)
xpos  the x position of the unit in tiles
ypos  the y position of the unit in tiles

Definition at line 1619 of file simcity.c.

References Int8, UIClipped(), UInt16, and winUnits.

void UIPaintWaterLoss UInt16    xpos,
UInt16    ypos
 

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 1596 of file simcity.c.

References PaintLossIcon(), and UInt16.

void UIPostLoadGame void   
 

UI post load game handler.

unused

Definition at line 919 of file simcity.c.

void UIProblemNotify problem_t    problem
 

notify that theres a problem in the city.

Parameters:
problem  the problem to notify.

Definition at line 1390 of file simcity.c.

References problemtable::alert, problemtable::entry, problem_t, problem_table, problemtable::set, problemtable::test, and UInt16.

void UIScrollDisplay dirType    direction
 

scroll the map in the appropriate direction

Todo:
double buffer to improve the rendering of the screen!

Definition at line 1780 of file simcity.c.

References dirType, DrawFieldWithoutInit(), dtDown, dtLeft, dtRight, dtUp, GETMINIMAPVISIBLE, Int16, LockZone(), lz_flags, lz_world, minimapIntersect(), minimapPaint(), UIFinishDrawing(), UIInitDrawing(), UInt16, UIPaintCursor(), UIPaintLocation(), and UnlockZone().

Int16 vkDoEvent UInt16    key [static]
 

process a virtual key press

Parameters:
key  the key that was pressed
Returns:
a processed hardbutton event or 0 for not mapped

Definition at line 2551 of file simcity.c.

References _silkKeys::event, HardButtonEvent(), silky, UInt16, and _silkKeys::vChar.


Variable Documentation

FormEventHandlerType* id2handler[] [static]
 

Initial value:

 {
        hPocketCity, 
        hBudget, 
        hMap , 
        hFiles, 
        hFilesNew, 
        hQuickList, 
        hExtraList, 
        hOptions, 
        hButtonConfig, 
        hQuery 
}

Definition at line 205 of file simcity.c.

UInt8 lockCalls = 0 [static]
 

\ brief counter of number of calls to lock screen

Definition at line 1452 of file simcity.c.

Referenced by UILockScreen(), and UIUnlockScreen().

const struct StatusPositions lrpositions[] [static]
 

Initial value:

 {
        { {0, 0} , {0, 1},  1  },  
        { {0, 0}, {0, 1},  8  }, 
        { {0, 0}, {0, 1},  1  |  8  }, 
        { {0, 0}, {0, 1},  4  |  8  } 
}
the positions of the items on screen - low resolution

Definition at line 1919 of file simcity.c.

RectangleType shapes[] [static]
 

Initial value:

 {
        { {0, 0}, {0, 10} },  
        { {0, 0}, {0, 10} }, 
        { {0, 0}, {0, 10} }, 
        { {0, 0}, {0, 10} } 
}
the default shape/size of the various locations

Definition at line 1911 of file simcity.c.

Referenced by DrawItem(), UICheckOnClick(), UIPaintCredits(), UIPaintLocation(), and UIPaintPopulation().

struct _silkKeys silky[] [static]
 

structure for mapping the silk keys to 'button keys'

The button keys are known 'event types'.

Referenced by buildSilkList(), and vkDoEvent().

UInt8 speedslist[] [static]
 

Initial value:

list of speeds in game

Definition at line 2335 of file simcity.c.

Referenced by cycleSpeed(), and speedOffset().


Generated on Mon Aug 30 19:44:18 2004 for pocketcity by doxygen1.2.18