diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2022-02-06 16:04:38 +0100 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2022-02-06 16:04:38 +0100 |
commit | d0ca838c7ab297036b4a7c45351761a48fe05efd (patch) | |
tree | f0f3cc006e8157d6bd699bd644b7dd7b35387ac2 /app/bin/ctrain.c | |
parent | fd6639655b399a79fb72f494786a4f57da9c90e7 (diff) | |
parent | 5d2c2b27a6323e2666378b986129b2a7c2c39e5c (diff) |
Update upstream source from tag 'upstream/5.2.2GA'
Update to upstream version '5.2.2GA'
with Debian dir 9c80045d0b4f9e463647bc8af8c090a673df4132
Diffstat (limited to 'app/bin/ctrain.c')
-rw-r--r-- | app/bin/ctrain.c | 346 |
1 files changed, 177 insertions, 169 deletions
diff --git a/app/bin/ctrain.c b/app/bin/ctrain.c index b15cb91..f113ee5 100644 --- a/app/bin/ctrain.c +++ b/app/bin/ctrain.c @@ -20,27 +20,17 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#ifndef WINDOWS -#include <errno.h> -#endif -#include <ctype.h> -#include <math.h> -#include <string.h> - -#define PRIVATE_EXTRADATA - #include "compound.h" +#include "cselect.h" #include "ctrain.h" #include "cundo.h" #include "custom.h" #include "fileio.h" -#include "i18n.h" #include "layout.h" -#include "messages.h" #include "param.h" #include "track.h" #include "trackx.h" -#include "utility.h" +#include "common-ui.h" long programMode; long maxCouplingSpeed = 100; @@ -53,7 +43,8 @@ static TRKTYP_T T_CAR = -1; typedef enum { ST_NotOnTrack, ST_StopManual, ST_EndOfTrack, ST_OpenTurnout, ST_NoRoom, ST_Crashed } trainStatus_e; -struct extraData { +typedef struct extraDataCar_t { + extraDataBase_t base; traverseTrack_t trvTrk; long state; carItem_p item; @@ -65,7 +56,7 @@ struct extraData { DIST_T distance; coOrd couplerPos[2]; unsigned int trkLayer; -}; +} extraDataCar_t; #define NOTALAYER (127) #define CAR_STATE_IGNORED (1L<<17) @@ -88,6 +79,15 @@ struct extraData { #define SetProcessed( XX ) (XX)->state |= CAR_STATE_PROCESSED #define ClrProcessed( XX ) (XX)->state &= ~CAR_STATE_PROCESSED +// Scroll the window before the train hits the edge +#define OFF_F( ORIG, SIZE, LO, HI ) \ + ( ( (HI).x < (ORIG).x+((SIZE).x)*0.2 && (ORIG).x > 0.0 ) || \ + ( (LO).x > (ORIG).x+((SIZE).x)*0.8 && (ORIG).x+(SIZE).x < mapD.size.x ) || \ + ( (HI).y < (ORIG).y+((SIZE).y)*0.2 && (ORIG).y > 0.0 ) || \ + ( (LO).y > (ORIG).y+((SIZE).y)*0.8 && (ORIG).y+(SIZE).y < mapD.size.y ) ) +#define OFF_FOLLOW( LO, HI ) \ + OFF_F( mainD.orig, mainD.size, LO, HI ) + static wButton_p newcarB; static void ControllerDialogSyncAll(void); @@ -99,6 +99,7 @@ static coOrd followCenter; static BOOL_T trainsTimeoutPending; static enum { TRAINS_STOP, TRAINS_RUN, TRAINS_IDLE, TRAINS_PAUSE } trainsState; static wIcon_p stopI, goI; +static wIcon_p stopB, goB; static void RestartTrains(void); static void DrawAllCars(void); static void UncoupleCars(track_p, track_p); @@ -113,7 +114,7 @@ static void PlaceCar(track_p); #define WALK_CARS_START( CAR, XX, DIR ) \ while (1) { \ - (XX) = GetTrkExtraData(CAR);\ + (XX) = GET_EXTRA_DATA(CAR, T_CAR, extraDataCar_t);\ { \ #define WALK_CARS_END( CAR, XX, DIR ) \ @@ -136,7 +137,7 @@ void CarGetPos( coOrd * posR, ANGLE_T * angleR) { - struct extraData * xx = GetTrkExtraData(car); + struct extraDataCar_t * xx = GET_EXTRA_DATA(car, T_CAR, extraDataCar_t); if (GetTrkType(car) != T_CAR) { AbortProg("getCarPos"); @@ -149,7 +150,7 @@ void CarGetPos( void CarSetVisible( track_p car) { - struct extraData * xx; + struct extraDataCar_t * xx; int dir; dir = 0; WALK_CARS_START(car, xx, dir) @@ -243,7 +244,7 @@ static void DescribeCar( char * str, CSIZE_T len) { - struct extraData *xx = GetTrkExtraData(trk); + struct extraDataCar_t *xx = GET_EXTRA_DATA(trk, T_CAR, extraDataCar_t); char * cp; coOrd size; CarItemSize(xx->item, &size); @@ -320,7 +321,7 @@ EXPORT void CheckCarTraverse(track_p track) { track_p car; for (car=NULL; TrackIterate(&car);) { if (GetTrkType(car) == T_CAR) { - struct extraData * xx = GetTrkExtraData(car); + struct extraDataCar_t * xx = GET_EXTRA_DATA(car, T_CAR, extraDataCar_t); if (xx->trvTrk.trk == track) { xx->trvTrk.trk=NULL; xx->status = ST_NotOnTrack; @@ -340,10 +341,10 @@ static void DrawCar( drawCmd_p d, wDrawColor color) { - struct extraData * xx = GetTrkExtraData(car); + struct extraDataCar_t * xx = GET_EXTRA_DATA(car, T_CAR, extraDataCar_t); int dir; vector_t coupler[2]; - struct extraData * xx1; + struct extraDataCar_t * xx1; int dir1; if (drawCarEnable == FALSE) { @@ -369,7 +370,7 @@ static void DrawCar( coupler[dir].pos = xx->couplerPos[dir]; if ((car1 = GetTrkEndTrk(car,dir))) { - xx1 = GetTrkExtraData(car1); + xx1 = GET_EXTRA_DATA(car1, T_CAR, extraDataCar_t); dir1 = (GetTrkEndTrk(car1,0)==car)?0:1; coupler[dir].angle = FindAngle(xx->couplerPos[dir], xx1->couplerPos[dir1]); } else { @@ -387,13 +388,13 @@ static DIST_T DistanceCar( track_p trk, coOrd * pos) { - struct extraData * xx = GetTrkExtraData(trk); + struct extraDataCar_t * xx = GET_EXTRA_DATA(trk, T_CAR, extraDataCar_t); DIST_T dist; coOrd pos1; coOrd size; if (IsIgnored(xx)) { - return 10000.0; + return DIST_INF; } CarItemSize(xx->item, @@ -420,7 +421,7 @@ static DIST_T DistanceCar( static void SetCarBoundingBox( track_p car) { - struct extraData * xx = GetTrkExtraData(car); + struct extraDataCar_t * xx = GET_EXTRA_DATA(car, T_CAR, extraDataCar_t); coOrd lo, hi, p[4]; int inx; coOrd size; @@ -464,10 +465,10 @@ track_p NewCar( ANGLE_T angle) { track_p trk; - struct extraData * xx; + struct extraDataCar_t * xx; trk = NewTrack(index, T_CAR, 2, sizeof(*xx)); /*SetEndPts( trk, 0 );*/ - xx = GetTrkExtraData(trk); + xx = GET_EXTRA_DATA(trk, T_CAR, extraDataCar_t); /*SetTrkVisible( trk, IsVisible(xx) );*/ xx->item = item; xx->trvTrk.pos = pos; @@ -483,7 +484,7 @@ track_p NewCar( static void DeleteCar( track_p trk) { - struct extraData * xx = GetTrkExtraData(trk); + struct extraDataCar_t * xx = GET_EXTRA_DATA(trk, T_CAR, extraDataCar_t); CarItemSetTrack(xx->item, NULL); } @@ -508,7 +509,7 @@ static void MoveCar( track_p car, coOrd pos) { - struct extraData *xx = GetTrkExtraData(car); + struct extraDataCar_t *xx = GET_EXTRA_DATA(car, T_CAR, extraDataCar_t); xx->trvTrk.pos.x += pos.x; xx->trvTrk.pos.y += pos.y; xx->trvTrk.trk = NULL; @@ -522,7 +523,7 @@ static void RotateCar( coOrd pos, ANGLE_T angle) { - struct extraData *xx = GetTrkExtraData(car); + struct extraDataCar_t *xx = GET_EXTRA_DATA(car, T_CAR, extraDataCar_t); Rotate(&xx->trvTrk.pos, pos, angle); xx->trvTrk.angle = NormalizeAngle(xx->trvTrk.angle + angle); xx->trvTrk.trk = NULL; @@ -536,6 +537,8 @@ static BOOL_T QueryCar(track_p trk, int query) switch (query) { case Q_NODRAWENDPT: return TRUE; + case Q_ISTRAIN: + return TRUE; default: return FALSE; @@ -547,14 +550,14 @@ static BOOL_T StoreCar( void **data, long * len) { - struct extraData *xx = GetTrkExtraData(car); + struct extraDataCar_t *xx = GET_EXTRA_DATA(car, T_CAR, extraDataCar_t); return StoreCarItem(xx->item,data,len); } static BOOL_T ReplayCar (track_p car, void *data,long len) { - struct extraData *xx = GetTrkExtraData(car); + struct extraDataCar_t *xx = GET_EXTRA_DATA(car, T_CAR, extraDataCar_t); return ReplayCarItem(xx->item,data,len); } @@ -633,10 +636,10 @@ typedef struct { static trainControlDlg_t * curTrainDlg; -static void SpeedRedraw(wDraw_p, void *, wPos_t, wPos_t); +static void SpeedRedraw(wDraw_p, void *, wWinPix_t, wWinPix_t); static void SpeedAction(wAction_t, coOrd); static void LocoListChangeEntry(track_p, track_p); -static void CmdTrainExit(void *); +static void CmdTrainExit(void * unused); drawCmd_t speedD = { NULL, @@ -658,18 +661,18 @@ static char * trainAutoReverseLabels[] = { N_("Auto Reverse"), NULL }; static paramData_t trainPLs[] = { #define I_LIST (0) #ifdef WINDOWS - /*0*/ { PD_DROPLIST, NULL, "list", PDO_NOPREF|PDO_NOPSHUPD, (void*)120, NULL, 0 }, + /*0*/ { PD_DROPLIST, NULL, "list", PDO_NOPREF|PDO_NOPSHUPD, I2VP(120), NULL, 0 }, #else /*0*/ { PD_LIST, NULL, "list", PDO_NOPREF|PDO_NOPSHUPD, &listData, NULL, 0 }, #endif #define I_STATUS (1) - { PD_MESSAGE, NULL, NULL, 0, (void*)120 }, + { PD_MESSAGE, NULL, NULL, 0, I2VP(120) }, #define I_POS (2) - { PD_MESSAGE, NULL, NULL, 0, (void*)120 }, + { PD_MESSAGE, NULL, NULL, 0, I2VP(120) }, #define I_SLIDER (3) { PD_DRAW, NULL, "speed", PDO_NOPSHUPD|PDO_DLGSETY, &speedParamData }, #define I_DIST (4) - { PD_STRING, NULL, "distance", PDO_DLGNEWCOLUMN, (void*)(100-SLIDER_WIDTH), NULL, BO_READONLY }, + { PD_STRING, NULL, "distance", PDO_DLGNEWCOLUMN, I2VP(100-SLIDER_WIDTH), NULL, BO_READONLY }, #define I_ZERO (5) { PD_BUTTON, NULL, "zeroDistance", PDO_NOPSHUPD|PDO_NOPREF|PDO_DLGHORZ, NULL, NULL, BO_ICON }, #define I_GOTO (6) @@ -683,10 +686,10 @@ static paramData_t trainPLs[] = { #define I_STOP (10) { PD_BUTTON, NULL, "stop", PDO_DLGWIDE, NULL, N_("Stop") }, #define I_SPEED (11) - { PD_MESSAGE, NULL, NULL, PDO_DLGIGNOREX, (void *)120 } + { PD_MESSAGE, NULL, NULL, PDO_DLGIGNOREX, I2VP(120) } }; -static paramGroup_t trainPG = { "train", 0, trainPLs, sizeof trainPLs/sizeof trainPLs[0] }; +static paramGroup_t trainPG = { "train", 0, trainPLs, COUNT( trainPLs ) }; typedef struct { @@ -723,12 +726,12 @@ static wIndex_t FindLoco( static void SpeedRedraw( wDraw_p d, void * context, - wPos_t w, - wPos_t h) + wWinPix_t w, + wWinPix_t h) { - wPos_t y, pts[4][2]; + wDrawPix_t y; trainControlDlg_p dlg = (trainControlDlg_p)context; - struct extraData * xx; + struct extraDataCar_t * xx; wDrawColor drawColor; wDrawClear(d); @@ -736,7 +739,7 @@ static void SpeedRedraw( return; } - xx = GetTrkExtraData(dlg->train); + xx = GET_EXTRA_DATA(dlg->train, T_CAR, extraDataCar_t); if (xx->speed > MAX_SPEED) { xx->speed = MAX_SPEED; @@ -746,25 +749,23 @@ static void SpeedRedraw( xx->speed = 0; } - y = (wPos_t)(xx->speed/MAX_SPEED*((SLIDER_HEIGHT-SLIDER_THICKNESS)) + y = (xx->speed/MAX_SPEED*((SLIDER_HEIGHT-SLIDER_THICKNESS)) +SLIDER_THICKNESS/2); drawColor = wDrawFindColor(wRGB(160, 160, 160)); - pts[0][1] = pts[1][1] = y-SLIDER_THICKNESS/2; - pts[2][1] = pts[3][1] = y+SLIDER_THICKNESS/2; - pts[0][0] = pts[3][0] = 0; - pts[1][0] = pts[2][0] = SLIDER_WIDTH; - wDrawPolygon(d, pts, NULL, 4, drawColor, 0, 0, 0, 1, 0); - drawColor = wDrawFindColor(wRGB(220, 220, 220)); - pts[0][1] = pts[1][1] = y+SLIDER_THICKNESS/2; - pts[2][1] = pts[3][1] = y; - pts[0][0] = pts[3][0] = 0; - pts[1][0] = pts[2][0] = SLIDER_WIDTH; - wDrawPolygon(d, pts, NULL, 4, drawColor, 0, 0, 0, 1, 0); - wDrawLine(d, 0, y, SLIDER_WIDTH, y, 1, wDrawLineSolid, drawColorRed, 0); - wDrawLine(d, 0, y+SLIDER_THICKNESS/2, SLIDER_WIDTH, y+SLIDER_THICKNESS/2, 1, - wDrawLineSolid, drawColorBlack, 0); - wDrawLine(d, 0, y-SLIDER_THICKNESS/2, SLIDER_WIDTH, y-SLIDER_THICKNESS/2, 1, - wDrawLineSolid, drawColorBlack, 0); + coOrd pos0, pos1, siz; + y /= speedD.dpi; + siz.x = SLIDER_WIDTH/speedD.dpi; + siz.y = SLIDER_THICKNESS/speedD.dpi; + pos0.x = 0.0; + pos0.y = y - siz.y/2.0; + DrawRectangle( &speedD, pos0, siz, drawColor, DRAW_FILL ); + pos1.x = siz.x; + pos1.y = pos0.y; + DrawLine( &speedD, pos0, pos1, 1, drawColorBlack ); + pos0.y = pos1.y = y; + DrawLine( &speedD, pos0, pos1, 3, drawColorRed ); + pos0.y = pos1.y = y + siz.y/2.0; + DrawLine( &speedD, pos0, pos1, 1, drawColorBlack ); sprintf(dlg->speedS, "%3d %s", (int)(units==UNITS_ENGLISH?xx->speed:xx->speed*1.6), (units==UNITS_ENGLISH?"mph":"km/h")); @@ -778,7 +779,7 @@ static void SpeedAction( coOrd pos) { trainControlDlg_p dlg = curTrainDlg; - struct extraData * xx; + struct extraDataCar_t * xx; FLOAT_T speed; BOOL_T startStop; @@ -786,7 +787,7 @@ static void SpeedAction( return; } - xx = GetTrkExtraData(dlg->train); + xx = GET_EXTRA_DATA(dlg->train, T_CAR, extraDataCar_t); switch (action) { case C_DOWN: @@ -841,7 +842,7 @@ static void SpeedAction( static void ControllerDialogSync( trainControlDlg_p dlg) { - struct extraData * xx=NULL; + struct extraDataCar_t * xx=NULL; wIndex_t inx; BOOL_T dir; BOOL_T followMe; @@ -870,7 +871,7 @@ static void ControllerDialogSync( if (dlg->train) { char * statusMsg; DIST_T speed; - xx = GetTrkExtraData(dlg->train); + xx = GET_EXTRA_DATA(dlg->train, T_CAR, extraDataCar_t); dir = xx->direction==0?0:1; speed = xx->speed; pos = xx->trvTrk.pos; @@ -996,7 +997,7 @@ static void LocoListChangeEntry( track_p newLoco) { wIndex_t inx = -1; - struct extraData * xx; + struct extraDataCar_t * xx; if (curTrainDlg == NULL) { return; @@ -1005,7 +1006,7 @@ static void LocoListChangeEntry( if (oldLoco && (inx=FindLoco(oldLoco))>=0) { if (newLoco) { locoList(inx).loco = newLoco; - xx = GetTrkExtraData(newLoco); + xx = GET_EXTRA_DATA(newLoco, T_CAR, extraDataCar_t); locoList(inx).running = IsOnTrack(xx) && xx->speed > 0; wListSetValues((wList_p)curTrainDlg->trainPGp->paramPtr[I_LIST].control, inx, CarItemNumber(xx->item), locoList(inx).running?goI:stopI, newLoco); @@ -1026,7 +1027,7 @@ static void LocoListChangeEntry( inx = locoList_da.cnt; DYNARR_APPEND(locoList_t, locoList_da, 10); locoList(inx).loco = newLoco; - xx = GetTrkExtraData(newLoco); + xx = GET_EXTRA_DATA(newLoco, T_CAR, extraDataCar_t); locoList(inx).running = IsOnTrack(xx) && xx->speed > 0; wListAddValue((wList_p)curTrainDlg->trainPGp->paramPtr[I_LIST].control, CarItemNumber(xx->item), locoList(inx).running?goI:stopI, newLoco); @@ -1048,7 +1049,7 @@ static void LocoListChangeEntry( static void LocoListInit(void) { track_p train; - struct extraData * xx; + struct extraDataCar_t * xx; locoList_da.cnt = 0; for (train=NULL; TrackIterate(&train);) { @@ -1056,7 +1057,7 @@ static void LocoListInit(void) continue; } - xx = GetTrkExtraData(train); + xx = GET_EXTRA_DATA(train, T_CAR, extraDataCar_t); if (!CarItemIsLoco(xx->item)) { continue; @@ -1083,13 +1084,13 @@ static void StopTrain( track_p train, trainStatus_e status) { - struct extraData * xx; + struct extraDataCar_t * xx; if (train == NULL) { return; } - xx = GetTrkExtraData(train); + xx = GET_EXTRA_DATA(train, T_CAR, extraDataCar_t); xx->speed = 0; xx->status = status; LocoListChangeEntry(train, train); @@ -1133,7 +1134,7 @@ static void MoveMainWindow( static void SetTrainDirection( track_p train) { - struct extraData *xx, *xx0=GetTrkExtraData(train); + struct extraDataCar_t *xx, *xx0=GET_EXTRA_DATA(train, T_CAR, extraDataCar_t); int dir0; track_p car; car = train; @@ -1161,7 +1162,7 @@ static void ControllerDialogUpdate( { trainControlDlg_p dlg = curTrainDlg; track_p train; - struct extraData * xx; + struct extraDataCar_t * xx; if (dlg == NULL) { return; @@ -1188,7 +1189,7 @@ static void ControllerDialogUpdate( } TrainTimeEndPause(); - xx = GetTrkExtraData(dlg->train); + xx = GET_EXTRA_DATA(dlg->train, T_CAR, extraDataCar_t); xx->distance = 0.0; ParamLoadMessage(dlg->trainPGp, I_DIST, FormatDistance(xx->distance)); ParamLoadControl(curTrainDlg->trainPGp, I_DIST); @@ -1201,7 +1202,7 @@ static void ControllerDialogUpdate( } TrainTimeEndPause(); - xx = GetTrkExtraData(dlg->train); + xx = GET_EXTRA_DATA(dlg->train, T_CAR, extraDataCar_t); followTrain = NULL; dlg->followMe = FALSE; ParamLoadControl(curTrainDlg->trainPGp, I_FOLLOW); @@ -1217,7 +1218,7 @@ static void ControllerDialogUpdate( if (*(long*)valueP) { followTrain = dlg->train; - xx = GetTrkExtraData(dlg->train); + xx = GET_EXTRA_DATA(dlg->train, T_CAR, extraDataCar_t); if (OFF_MAIND(xx->trvTrk.pos, xx->trvTrk.pos)) { MoveMainWindow(xx->trvTrk.pos, xx->trvTrk.angle); @@ -1235,7 +1236,7 @@ static void ControllerDialogUpdate( return; } - xx = GetTrkExtraData(dlg->train); + xx = GET_EXTRA_DATA(dlg->train, T_CAR, extraDataCar_t); xx->autoReverse = *(long*)valueP!=0; break; @@ -1244,7 +1245,7 @@ static void ControllerDialogUpdate( return; } - xx = GetTrkExtraData(dlg->train); + xx = GET_EXTRA_DATA(dlg->train, T_CAR, extraDataCar_t); dlg->direction = xx->direction = !xx->direction; wButtonSetLabel((wButton_p)pg->paramPtr[I_DIR].control, (dlg->direction?_("Reverse"):_("Forward"))); @@ -1303,6 +1304,8 @@ static trainControlDlg_p CreateTrainControlDlg(void) dlg->trainPGp = &trainPG; dlg->win = ParamCreateDialog(dlg->trainPGp, _("Train Control"), NULL, NULL, NULL, FALSE, NULL, 0, ControllerDialogUpdate); + speedD.size.x = SLIDER_WIDTH/speedD.dpi; + speedD.size.y = SLIDER_HEIGHT/speedD.dpi; return dlg; } @@ -1323,7 +1326,7 @@ static track_p followTrain = NULL; static void DrawAllCars(void) { track_p car; - struct extraData * xx; + struct extraDataCar_t * xx; coOrd size, lo, hi; BOOL_T drawCarEnable1 = drawCarEnable; drawCarEnable = TRUE; @@ -1333,7 +1336,7 @@ static void DrawAllCars(void) for (car=NULL; TrackIterate(&car);) { if (GetTrkType(car) == T_CAR) { - xx = GetTrkExtraData(car); + xx = GET_EXTRA_DATA(car, T_CAR, extraDataCar_t); CarItemSize(xx->item, &size); /* TODO assumes xx->trvTrk.pos is the car center */ lo.x = xx->trvTrk.pos.x - size.x/2.0; @@ -1357,7 +1360,7 @@ static DIST_T GetTrainLength2( BOOL_T * dir) { DIST_T length = 0, carLength; - struct extraData * xx; + struct extraDataCar_t * xx; WALK_CARS_START(*car0, xx, *dir) carLength = CarItemCoupledLength(xx->item); @@ -1383,7 +1386,7 @@ static DIST_T GetTrainLength( static void PlaceCar( track_p car) { - struct extraData *xx = GetTrkExtraData(car); + struct extraDataCar_t *xx = GET_EXTRA_DATA(car, T_CAR, extraDataCar_t); DIST_T dists[2]; CarItemPlace(xx->item, &xx->trvTrk, dists); @@ -1414,13 +1417,13 @@ static track_p FindCar( { coOrd pos0, pos1; track_p trk, trk1; - DIST_T dist1 = 100000, dist; - struct extraData * xx; + DIST_T dist1 = DIST_INF, dist; + struct extraDataCar_t * xx; trk1 = NULL; for (trk=NULL; TrackIterate(&trk);) { if (GetTrkType(trk) == T_CAR) { - xx = GetTrkExtraData(trk); + xx = GET_EXTRA_DATA(trk, T_CAR, extraDataCar_t); if (IsIgnored(xx)) { continue; @@ -1450,7 +1453,7 @@ static track_p FindMasterLoco( track_p train, int * dirR) { - struct extraData *xx0; + struct extraDataCar_t *xx0; int dir; for (dir = 0; dir<2; dir++) { @@ -1480,7 +1483,7 @@ static track_p PickMasterLoco( int dir) { track_p loco=NULL; - struct extraData *xx; + struct extraDataCar_t *xx; WALK_CARS_START(car, xx, dir) if (CarItemIsLoco(xx->item)) { @@ -1499,7 +1502,7 @@ static track_p PickMasterLoco( return NULL; } - xx = GetTrkExtraData(loco); + xx = GET_EXTRA_DATA(loco, T_CAR, extraDataCar_t); SetLocoMaster(xx); xx->speed = 0; LOG(log_trainMove, 1, ("%s becomes master\n", CarItemNumber(xx->item))) @@ -1558,12 +1561,12 @@ static void CoupleCars( track_p car2, int dir2) { - struct extraData * xx1, * xx2; + struct extraDataCar_t * xx1, * xx2; track_p loco1, loco2; track_p car; int dir; - xx1 = GetTrkExtraData(car1); - xx2 = GetTrkExtraData(car2); + xx1 = GET_EXTRA_DATA(car1, T_CAR, extraDataCar_t); + xx2 = GET_EXTRA_DATA(car2, T_CAR, extraDataCar_t); if (GetTrkEndTrk(car1,dir1) != NULL || GetTrkEndTrk(car2,dir2) != NULL) { LOG(log_trainMove, 1, ("coupleCars - already coupled\n")) @@ -1604,8 +1607,8 @@ static void CoupleCars( } if ((loco1 != NULL && loco2 != NULL)) { - xx1 = GetTrkExtraData(loco1); - xx2 = GetTrkExtraData(loco2); + xx1 = GET_EXTRA_DATA(loco1, T_CAR, extraDataCar_t); + xx2 = GET_EXTRA_DATA(loco2, T_CAR, extraDataCar_t); if (xx1->speed == 0) { ClrLocoMaster(xx1); @@ -1651,7 +1654,7 @@ static void PlaceCars( long crashSpeed, BOOL_T crashFlip) { - struct extraData *xx0 = GetTrkExtraData(car0), *xx; + struct extraDataCar_t *xx0 = GET_EXTRA_DATA(car0, T_CAR, extraDataCar_t), *xx; int dir; traverseTrack_t trvTrk; DIST_T length; @@ -1715,14 +1718,14 @@ static void CrashTrain( BOOL_T flip) { track_p loco; - struct extraData *xx; + struct extraDataCar_t *xx; loco = FindMasterLoco(car,NULL); if (loco != NULL) { StopTrain(loco, ST_Crashed); } - xx = GetTrkExtraData(car); + xx = GET_EXTRA_DATA(car, T_CAR, extraDataCar_t); xx->trvTrk = *trvTrkP; if (dir) { @@ -1751,13 +1754,13 @@ static BOOL_T CheckCoupling( BOOL_T doCheckCrash) { track_p car1; - struct extraData *xx0, *xx1; + struct extraDataCar_t *xx0, *xx1; coOrd pos1; - DIST_T dist0, distc, dist=100000.0; + DIST_T dist0, distc, dist=DIST_INF; int dir0, dir1, dirl; ANGLE_T angle; traverseTrack_t trvTrk0, trvTrk1; - xx0 = xx1 = GetTrkExtraData(car0); + xx0 = xx1 = GET_EXTRA_DATA(car0, T_CAR, extraDataCar_t); /* find length of train from loco to start and end */ dir0 = dir00; dist0 = GetTrainLength2(&car0, &dir0); @@ -1775,7 +1778,7 @@ static BOOL_T CheckCoupling( return TRUE; } - xx1 = GetTrkExtraData(car1); + xx1 = GET_EXTRA_DATA(car1, T_CAR, extraDataCar_t); if (!IsOnTrack(xx1)) { return TRUE; @@ -1866,7 +1869,7 @@ static BOOL_T CheckCoupling( xx1 = NULL; if (loco1) { - xx1 = GetTrkExtraData(loco1); + xx1 = GET_EXTRA_DATA(loco1, T_CAR, extraDataCar_t); speed1 = (long)xx1->speed; if (car1 == loco1) { @@ -1908,9 +1911,9 @@ static void PlaceTrain( BOOL_T doCheckCoupling) { track_p car_curr; - struct extraData *xx0; + struct extraDataCar_t *xx0; int dir0; - xx0 = GetTrkExtraData(car0); + xx0 = GET_EXTRA_DATA(car0, T_CAR, extraDataCar_t); LOG(log_trainMove, 2, (" placeTrain: %s [%0.3f %0.3f] A%0.3f", CarItemNumber(xx0->item), xx0->trvTrk.pos.x, xx0->trvTrk.pos.y, xx0->trvTrk.angle)) @@ -1918,7 +1921,7 @@ static void PlaceTrain( for (dir0=0; dir0<2; dir0++) { int dir; - struct extraData *xx; + struct extraDataCar_t *xx; car_curr = car0; dir = dir0; xx = xx0; @@ -1955,7 +1958,7 @@ static void PlaceTrainInit( ANGLE_T angle0, BOOL_T doCheckCoupling) { - struct extraData * xx = GetTrkExtraData(car0); + struct extraDataCar_t * xx = GET_EXTRA_DATA(car0, T_CAR, extraDataCar_t); xx->trvTrk.trk = trk0; xx->trvTrk.dist = xx->trvTrk.length = -1; xx->trvTrk.pos = pos0; @@ -1968,7 +1971,7 @@ static void FlipTrain( track_p train) { DIST_T d0, d1; - struct extraData * xx; + struct extraDataCar_t * xx; if (train == NULL) { return; @@ -1976,7 +1979,7 @@ static void FlipTrain( d0 = GetTrainLength(train, 0); d1 = GetTrainLength(train, 1); - xx = GetTrkExtraData(train); + xx = GET_EXTRA_DATA(train, T_CAR, extraDataCar_t); TraverseTrack2(&xx->trvTrk, d0-d1); FlipTraverseTrack(&xx->trvTrk); xx->trvTrk.length = -1; @@ -1989,7 +1992,7 @@ static BOOL_T MoveTrain( long timeD) { DIST_T ips, dist0, dist1; - struct extraData *xx, *xx1; + struct extraDataCar_t *xx, *xx1; traverseTrack_t trvTrk; DIST_T length; track_p car1; @@ -2000,7 +2003,7 @@ static BOOL_T MoveTrain( return FALSE; } - xx = GetTrkExtraData(train); + xx = GET_EXTRA_DATA(train, T_CAR, extraDataCar_t); if (xx->speed <= 0) { return FALSE; @@ -2086,7 +2089,7 @@ static BOOL_T MoveTrain( } followTrain = NULL; - } else if (OFF_MAIND(xx->trvTrk.pos, xx->trvTrk.pos)) { + } else if (OFF_FOLLOW(xx->trvTrk.pos, xx->trvTrk.pos)) { MoveMainWindow(xx->trvTrk.pos, NormalizeAngle(xx->trvTrk.angle+(xx->direction?180.0:0.0))); followCenter = mainCenter; @@ -2102,14 +2105,14 @@ static BOOL_T MoveTrains(long timeD) { BOOL_T trains_moved = FALSE; track_p train; - struct extraData * xx; + struct extraDataCar_t * xx; for (train=NULL; TrackIterate(&train);) { if (GetTrkType(train) != T_CAR) { continue; } - xx = GetTrkExtraData(train); + xx = GET_EXTRA_DATA(train, T_CAR, extraDataCar_t); if (!CarItemIsLoco(xx->item)) { continue; @@ -2298,7 +2301,7 @@ void AttachTrains(void) { track_p car; track_p loco; - struct extraData * xx; + struct extraDataCar_t * xx; coOrd pos; track_p trk; ANGLE_T angle; @@ -2312,7 +2315,7 @@ void AttachTrains(void) continue; } - xx = GetTrkExtraData(car); + xx = GET_EXTRA_DATA(car, T_CAR, extraDataCar_t); ClrProcessed(xx); } @@ -2321,7 +2324,7 @@ void AttachTrains(void) continue; } - xx = GetTrkExtraData(car); + xx = GET_EXTRA_DATA(car, T_CAR, extraDataCar_t); if (IsProcessed(xx)) { continue; @@ -2330,7 +2333,7 @@ void AttachTrains(void) loco = FindMasterLoco(car, NULL); if (loco != NULL) { - xx = GetTrkExtraData(loco); + xx = GET_EXTRA_DATA(loco, T_CAR, extraDataCar_t); } else { loco = car; } @@ -2390,7 +2393,7 @@ void AttachTrains(void) continue; } - xx = GetTrkExtraData(car); + xx = GET_EXTRA_DATA(car, T_CAR, extraDataCar_t); ClrProcessed(xx); } } @@ -2399,7 +2402,7 @@ void AttachTrains(void) static void UpdateTrainAttachment(void) { track_p trk; - struct extraData * xx; + struct extraDataCar_t * xx; for (trk=NULL; TrackIterate(&trk);) { ClrTrkBits(trk, TB_CARATTACHED); @@ -2407,7 +2410,7 @@ static void UpdateTrainAttachment(void) for (trk=NULL; TrackIterate(&trk);) { if (GetTrkType(trk) == T_CAR) { - xx = GetTrkExtraData(trk); + xx = GET_EXTRA_DATA(trk, T_CAR, extraDataCar_t); if (xx->trvTrk.trk != NULL) { SetTrkBits(xx->trvTrk.trk, TB_CARATTACHED); @@ -2422,7 +2425,7 @@ static BOOL_T TrainOnMovableTrack( track_p *trainR) { track_p train; - struct extraData * xx; + struct extraDataCar_t * xx; int dir; for (train=NULL; TrackIterate(&train);) { @@ -2430,7 +2433,7 @@ static BOOL_T TrainOnMovableTrack( continue; } - xx = GetTrkExtraData(train); + xx = GET_EXTRA_DATA(train, T_CAR, extraDataCar_t); if (IsOnTrack(xx)) { if (xx->trvTrk.trk == trk) { @@ -2493,8 +2496,8 @@ static STATUS_T CmdTrain(wAction_t action, coOrd pos) ANGLE_T angle1; EPINX_T ep0, ep1; int dir; - struct extraData * xx=NULL; - wPos_t w, h; + struct extraDataCar_t * xx=NULL; + wWinPix_t w, h; switch (action) { case C_START: @@ -2507,11 +2510,11 @@ static STATUS_T CmdTrain(wAction_t action, coOrd pos) if (CarAvailableCount() <= 0) { if (NoticeMessage(MSG_NO_CARS, _("Yes"), _("No")) > 0) { - DoCarDlg(); + DoCarDlg(NULL); DoChangeNotification(CHANGE_PARAMS); } } - + SetAllTrackSelect( FALSE ); EnableCommands(); if (curTrainDlg == NULL) { @@ -2525,7 +2528,7 @@ static STATUS_T CmdTrain(wAction_t action, coOrd pos) tempSegs_da.cnt = 0; DYNARR_SET(trkSeg_t, tempSegs_da, 8); RestartTrains(); - wButtonSetLabel(trainPauseB, (char*)goI); + wButtonSetLabel(trainPauseB, (char*)goB); trainTime0 = 0; AttachTrains(); curTrainDlg->train = NULL; @@ -2534,7 +2537,7 @@ static STATUS_T CmdTrain(wAction_t action, coOrd pos) LocoListInit(); ControllerDialogSync(curTrainDlg); wShow(curTrainDlg->win); - wControlShow((wControl_p)newcarB, (toolbarSet&(1<<BG_HOTBAR)) == 0); + wControlShow((wControl_p)newcarB, (toolbarSet&(1<<BG_TRAIN))); currCarItemPtr = NULL; TempRedraw(); // CmdTrain C_START return C_CONTINUE; @@ -2568,7 +2571,7 @@ static STATUS_T CmdTrain(wAction_t action, coOrd pos) return C_CONTINUE; } - xx = GetTrkExtraData(currCar); + xx = GET_EXTRA_DATA(currCar, T_CAR, extraDataCar_t); xx->pencils = FALSE; dist = CarItemCoupledLength(xx->item)/2.0; Translate(&pos, xx->trvTrk.pos, xx->trvTrk.angle, dist); @@ -2605,13 +2608,13 @@ static STATUS_T CmdTrain(wAction_t action, coOrd pos) if (logTable(log_trainMove).level >= 1) { if (currCar) { - xx = GetTrkExtraData(currCar); + xx = GET_EXTRA_DATA(currCar, T_CAR, extraDataCar_t); LogPrintf("selected %s\n", CarItemNumber(xx->item)); for (dir=0; dir<2; dir++) { int dir1 = dir; track_p car1 = currCar; - struct extraData * xx1 = GetTrkExtraData(car1); + struct extraDataCar_t * xx1 = GET_EXTRA_DATA(car1, T_CAR, extraDataCar_t); LogPrintf("dir=%d\n", dir1); WALK_CARS_START(car1, xx1, dir1) LogPrintf(" %s [%0.3f,%d]\n", CarItemNumber(xx1->item), xx1->trvTrk.angle, @@ -2642,7 +2645,7 @@ static STATUS_T CmdTrain(wAction_t action, coOrd pos) pos.x += delta.x; pos.y += delta.y; pos0 = pos; - xx = GetTrkExtraData(currCar); + xx = GET_EXTRA_DATA(currCar, T_CAR, extraDataCar_t); trk0 = OnTrack(&pos0, FALSE, TRUE); if (/*currCarItemPtr != NULL &&*/ trk0) { @@ -2672,7 +2675,7 @@ static STATUS_T CmdTrain(wAction_t action, coOrd pos) trk0 = FindMasterLoco(currCar, NULL); if (trk0) { - xx = GetTrkExtraData(trk0); + xx = GET_EXTRA_DATA(trk0, T_CAR, extraDataCar_t); if (!IsOnTrack(xx) || xx->speed <= 0) { StopTrain(trk0, ST_StopManual); @@ -2703,7 +2706,7 @@ static STATUS_T CmdTrain(wAction_t action, coOrd pos) QueryTrack(trk0, Q_CAN_NEXT_POSITION) && TrainOnMovableTrack(trk0, &trk1)) { if (trk1) { - xx = GetTrkExtraData(trk1); + xx = GET_EXTRA_DATA(trk1, T_CAR, extraDataCar_t); pos1 = xx->trvTrk.pos; angle1 = xx->trvTrk.angle; } else { @@ -2750,7 +2753,7 @@ static STATUS_T CmdTrain(wAction_t action, coOrd pos) return C_CONTINUE; } - xx = GetTrkExtraData(trainFuncCar); + xx = GET_EXTRA_DATA(trainFuncCar, T_CAR, extraDataCar_t); if (xx->pencils) { wMenuPushEnable(trainPopupMI[DO_PENCILS_OFF], TRUE); wMenuPushEnable(trainPopupMI[DO_PENCILS_ON], FALSE); @@ -2768,7 +2771,7 @@ static STATUS_T CmdTrain(wAction_t action, coOrd pos) !IsLocoMaster(xx)); if (trk0) { - xx = GetTrkExtraData(trk0); + xx = GET_EXTRA_DATA(trk0, T_CAR, extraDataCar_t); } wMenuPushEnable(trainPopupMI[DO_CHANGEDIR], trk0!=NULL); @@ -2853,22 +2856,24 @@ STATUS_T CmdCarDescAction( #include "bitmaps/train.xpm" #include "bitmaps/exit.xpm" -#include "bitmaps/newcar.xpm" +#include "bitmaps/new-car.xpm" #include "bitmaps/zero.xpm" -#include "bitmaps/ballgreen.xpm" -#include "bitmaps/ballred.xpm" +#include "bitmaps/go.xpm" +#include "bitmaps/stop.xpm" +#include "bitmaps/greendot.xpm" +#include "bitmaps/reddot.xpm" -static void CmdTrainStopGo(void * junk) +static void CmdTrainStopGo(void * unused) { wIcon_p icon; if (trainsState == TRAINS_STOP) { - icon = goI; + icon = goB; RestartTrains(); } else { trainsState = TRAINS_STOP; - icon = stopI; + icon = stopB; TrainTimeEndPause(); } @@ -2894,7 +2899,7 @@ static BOOL_T TrainStopGoPlayback(char * line) } -static void CmdTrainExit(void * junk) +static void CmdTrainExit(void * unused) { Reset(); InfoSubstituteControls(NULL, NULL); @@ -2904,7 +2909,7 @@ static void CmdTrainExit(void * junk) static void TrainFunc( void * action) { - struct extraData * xx, *xx1; + struct extraDataCar_t * xx, *xx1; ANGLE_T angle; int dir; track_p loco; @@ -2918,12 +2923,12 @@ static void TrainFunc( return; } - xx = GetTrkExtraData(trainFuncCar); + xx = GET_EXTRA_DATA(trainFuncCar, T_CAR, extraDataCar_t); angle = FindAngle(xx->trvTrk.pos, trainFuncPos); angle = NormalizeAngle(angle-xx->trvTrk.angle); dir = (angle>90&&angle<270); - switch ((int)(long)action) { + switch (VP2L(action)) { case DO_UNCOUPLE: if (GetTrkEndTrk(trainFuncCar,dir)) { UncoupleCars(trainFuncCar, GetTrkEndTrk(trainFuncCar,dir)); @@ -3010,7 +3015,7 @@ static void TrainFunc( WALK_CARS_START(trainFuncCar, xx, dir) if (temp0) { - xx1 = GetTrkExtraData(temp0); + xx1 = GET_EXTRA_DATA(temp0, T_CAR, extraDataCar_t); temp0->deleted = TRUE; /*DeleteTrack( temp0, FALSE );*/ CarItemUpdate(xx1->item); @@ -3020,7 +3025,7 @@ static void TrainFunc( WALK_CARS_END(trainFuncCar, xx, dir) if (temp0) { - xx1 = GetTrkExtraData(temp0); + xx1 = GET_EXTRA_DATA(temp0, T_CAR, extraDataCar_t); temp0->deleted = TRUE; /*DeleteTrack( temp0, FALSE );*/ CarItemUpdate(xx1->item); @@ -3043,7 +3048,7 @@ static void TrainFunc( LOG(log_trainMove, 1, ("%s gets master\n", CarItemNumber(xx->item))) if (loco) { - xx1 = GetTrkExtraData(loco); + xx1 = GET_EXTRA_DATA(loco, T_CAR, extraDataCar_t); ClrLocoMaster(xx1); LOG(log_trainMove, 1, ("%s looses master\n", CarItemNumber(xx1->item))) xx->speed = xx1->speed; @@ -3060,7 +3065,7 @@ static void TrainFunc( loco = FindMasterLoco(trainFuncCar, NULL); if (loco) { - xx = GetTrkExtraData(loco); + xx = GET_EXTRA_DATA(loco, T_CAR, extraDataCar_t); xx->direction = !xx->direction; SetTrainDirection(loco); ControllerDialogSync(curTrainDlg); @@ -3095,40 +3100,43 @@ void InitCmdTrain(wMenu_p menu) log_trainPlayback = LogFindIndex("trainPlayback"); trainPLs[I_ZERO].winLabel = (char*)wIconCreatePixMap(zero_xpm); ParamRegister(&trainPG); - trainCmdInx = AddMenuButton(menu, CmdTrain, "cmdTrain", _("Train"), - wIconCreatePixMap(train_xpm), LEVEL0_50, IC_POPUP3|IC_LCLICK|IC_RCLICK, 0, + trainCmdInx = AddMenuButton(menu, CmdTrain, "cmdTrain", _("Run Trains"), + wIconCreatePixMap(train_xpm[iconSize]), LEVEL0_50, IC_POPUP3|IC_LCLICK|IC_RCLICK, 0, NULL); - stopI = wIconCreatePixMap(ballred); - goI = wIconCreatePixMap(ballgreen); - trainPauseB = AddToolbarButton("cmdTrainPause", stopI, IC_MODETRAIN_ONLY, + stopI = wIconCreatePixMap(reddot); + goI = wIconCreatePixMap(greendot); + stopB = wIconCreatePixMap(stop_xpm[iconSize]); + goB = wIconCreatePixMap(go_xpm[iconSize]); + trainPauseB = AddToolbarButton("cmdTrainPause", stopB, IC_MODETRAIN_ONLY, CmdTrainStopGo, NULL); - AddToolbarButton("cmdTrainExit", wIconCreatePixMap(exit_xpm), IC_MODETRAIN_ONLY, + AddToolbarButton("cmdTrainExit", wIconCreatePixMap(exit_xpm[iconSize]), IC_MODETRAIN_ONLY, CmdTrainExit, NULL); - newcarB = AddToolbarButton("cmdTrainNewCar", wIconCreatePixMap(newcar_xpm), + newcarB = AddToolbarButton("cmdTrainNewCar", wIconCreatePixMap(new_car_xpm[iconSize]), IC_MODETRAIN_ONLY, CarItemLoadList, NULL); T_CAR = InitObject(&carCmds); - trainPopupM = MenuRegister("Train Commands"); + + trainPopupM = MenuRegister("Train Commands"); trainPopupMI[DO_UNCOUPLE] = wMenuPushCreate(trainPopupM, "", _("Uncouple"), 0, - TrainFunc, (void*)DO_UNCOUPLE); + TrainFunc, I2VP(DO_UNCOUPLE)); trainPopupMI[DO_FLIPCAR] = wMenuPushCreate(trainPopupM, "", _("Flip Car"), 0, - TrainFunc, (void*)DO_FLIPCAR); + TrainFunc, I2VP(DO_FLIPCAR)); trainPopupMI[DO_PENCILS_ON] = wMenuPushCreate(trainPopupM, "", _("Clearance Lines On"), 0, - TrainFunc, (void*)DO_PENCILS_ON); + TrainFunc, I2VP(DO_PENCILS_ON)); trainPopupMI[DO_PENCILS_OFF] = wMenuPushCreate(trainPopupM, "", _("Clearance Lines Off"), 0, - TrainFunc, (void*)DO_PENCILS_OFF); + TrainFunc, I2VP(DO_PENCILS_OFF)); trainPopupMI[DO_FLIPTRAIN] = wMenuPushCreate(trainPopupM, "", _("Flip Train"), - 0, TrainFunc, (void*)DO_FLIPTRAIN); + 0, TrainFunc, I2VP(DO_FLIPTRAIN)); trainPopupMI[DO_MUMASTER] = wMenuPushCreate(trainPopupM, "", _("MU Master"), - 0, TrainFunc, (void*)DO_MUMASTER); + 0, TrainFunc, I2VP(DO_MUMASTER)); trainPopupMI[DO_CHANGEDIR] = wMenuPushCreate(trainPopupM, "", - _("Change Direction"), 0, TrainFunc, (void*)DO_CHANGEDIR); + _("Change Direction"), 0, TrainFunc, I2VP(DO_CHANGEDIR)); trainPopupMI[DO_STOP] = wMenuPushCreate(trainPopupM, "", _("Stop"), 0, - TrainFunc, (void*)DO_STOP); + TrainFunc, I2VP(DO_STOP)); wMenuSeparatorCreate(trainPopupM); trainPopupMI[DO_DELCAR] = wMenuPushCreate(trainPopupM, "", _("Remove Car"), - 0, TrainFunc, (void*)DO_DELCAR); + 0, TrainFunc, I2VP(DO_DELCAR)); trainPopupMI[DO_DELTRAIN] = wMenuPushCreate(trainPopupM, "", - _("Remove Train"), 0, TrainFunc, (void*)DO_DELTRAIN); + _("Remove Train"), 0, TrainFunc, I2VP(DO_DELTRAIN)); AddPlaybackProc("TRAINSTOPGO", (playbackProc_p)TrainStopGoPlayback, NULL); AddPlaybackProc("TRAINPAUSE", (playbackProc_p)TrainTimeDoPause, NULL); AddPlaybackProc("TRAINMOVIE", (playbackProc_p)TrainDoMovie, NULL); |