vehicle.c
changeset 395 788a9bba0889
parent 337 cbe0c766c947
child 410 0efd84450b01
equal deleted inserted replaced
394:675c52a63cb6 395:788a9bba0889
   106 	v->top_coord = pt.y;
   106 	v->top_coord = pt.y;
   107 	v->right_coord = pt.x + sd->xsize + 2;
   107 	v->right_coord = pt.x + sd->xsize + 2;
   108 	v->bottom_coord = pt.y + sd->ysize + 2;
   108 	v->bottom_coord = pt.y + sd->ysize + 2;
   109 }
   109 }
   110 
   110 
   111 void UpdateCheckpointSign(Checkpoint *cp)
   111 void UpdateWaypointSign(Waypoint *cp)
   112 {
   112 {
   113 	Point pt = RemapCoords2(GET_TILE_X(cp->xy)*16, GET_TILE_Y(cp->xy)*16);
   113 	Point pt = RemapCoords2(GET_TILE_X(cp->xy)*16, GET_TILE_Y(cp->xy)*16);
   114 	SET_DPARAM16(0, cp - _checkpoints);
   114 	SET_DPARAM16(0, cp - _waypoints);
   115 	UpdateViewportSignPos(&cp->sign, pt.x, pt.y - 0x20, STR_CHECKPOINT_VIEWPORT);
   115 	UpdateViewportSignPos(&cp->sign, pt.x, pt.y - 0x20, STR_WAYPOINT_VIEWPORT);
   116 }
   116 }
   117 
   117 
   118 void RedrawCheckpointSign(Checkpoint *cp)
   118 void RedrawWaypointSign(Waypoint *cp)
   119 {
   119 {
   120 	MarkAllViewportsDirty(
   120 	MarkAllViewportsDirty(
   121 		cp->sign.left - 6,
   121 		cp->sign.left - 6,
   122 		cp->sign.top,
   122 		cp->sign.top,
   123 		cp->sign.left + (cp->sign.width_1 << 2) + 12,
   123 		cp->sign.left + (cp->sign.width_1 << 2) + 12,
   126 
   126 
   127 // Called after load to update coordinates
   127 // Called after load to update coordinates
   128 void AfterLoadVehicles()
   128 void AfterLoadVehicles()
   129 {
   129 {
   130 	Vehicle *v;
   130 	Vehicle *v;
   131 	Checkpoint *cp;
   131 	Waypoint *cp;
   132 
   132 
   133 	FOR_ALL_VEHICLES(v) {
   133 	FOR_ALL_VEHICLES(v) {
   134 		if (v->type != 0) {
   134 		if (v->type != 0) {
   135 			v->left_coord = INVALID_COORD;
   135 			v->left_coord = INVALID_COORD;
   136 			VehiclePositionChanged(v);
   136 			VehiclePositionChanged(v);
   145 				v->schedule_ptr = NULL;
   145 				v->schedule_ptr = NULL;
   146 #endif
   146 #endif
   147 		}
   147 		}
   148 	}
   148 	}
   149 
   149 
   150 	// update checkpoint signs
   150 	// update waypoint signs
   151 	for(cp=_checkpoints; cp != endof(_checkpoints); cp++) if (cp->xy) UpdateCheckpointSign(cp);
   151 	for(cp=_waypoints; cp != endof(_waypoints); cp++) if (cp->xy) UpdateWaypointSign(cp);
   152 }
   152 }
   153 
   153 
   154 
   154 
   155 static Vehicle *InitializeVehicle(Vehicle *v)
   155 static Vehicle *InitializeVehicle(Vehicle *v)
   156 {
   156 {
   292 	Vehicle *v;
   292 	Vehicle *v;
   293 	int i;
   293 	int i;
   294 
   294 
   295 	// clear it...
   295 	// clear it...
   296 	memset(&_vehicles, 0, sizeof(_vehicles));
   296 	memset(&_vehicles, 0, sizeof(_vehicles));
   297 	memset(&_checkpoints, 0, sizeof(_checkpoints));
   297 	memset(&_waypoints, 0, sizeof(_waypoints));
   298 	memset(&_depots, 0, sizeof(_depots));
   298 	memset(&_depots, 0, sizeof(_depots));
   299 
   299 
   300 	// setup indexes..
   300 	// setup indexes..
   301 	i = 0;
   301 	i = 0;
   302 	FOR_ALL_VEHICLES(v)
   302 	FOR_ALL_VEHICLES(v)
   366 	}
   366 	}
   367 
   367 
   368 	return free_dep;
   368 	return free_dep;
   369 }
   369 }
   370 
   370 
   371 Checkpoint *AllocateCheckpoint()
   371 Waypoint *AllocateWaypoint()
   372 {
   372 {
   373 	Checkpoint *cp;
   373 	Waypoint *cp;
   374 
   374 
   375 	for(cp = _checkpoints; cp != endof(_checkpoints); cp++) {
   375 	for(cp = _waypoints; cp != endof(_waypoints); cp++) {
   376 		if (cp->xy == 0)
   376 		if (cp->xy == 0)
   377 			return cp;
   377 			return cp;
   378 	}
   378 	}
   379 
   379 
   380 	return NULL;
   380 	return NULL;
   381 }
   381 }
   382 
   382 
   383 uint GetCheckpointByTile(uint tile)
   383 uint GetWaypointByTile(uint tile)
   384 {
   384 {
   385 	Checkpoint *cp;
   385 	Waypoint *cp;
   386 	int i=0;
   386 	int i=0;
   387 	for(cp=_checkpoints; cp->xy != (TileIndex)tile; cp++) { i++; }
   387 	for(cp=_waypoints; cp->xy != (TileIndex)tile; cp++) { i++; }
   388 	return i;
   388 	return i;
   389 }
   389 }
   390 
   390 
   391 
   391 
   392 Vehicle *IsScheduleShared(Vehicle *u)
   392 Vehicle *IsScheduleShared(Vehicle *u)
  1799 	while ((index = SlIterateArray()) != -1) {
  1799 	while ((index = SlIterateArray()) != -1) {
  1800 		SlObject(&_depots[index], _depot_desc);
  1800 		SlObject(&_depots[index], _depot_desc);
  1801 	}
  1801 	}
  1802 }
  1802 }
  1803 
  1803 
  1804 static const byte _checkpoint_desc[] = {
  1804 static const byte _waypoint_desc[] = {
  1805 	SLE_VAR(Checkpoint,xy,								SLE_UINT16),
  1805 	SLE_VAR(Waypoint,xy,								SLE_UINT16),
  1806 	SLE_VAR(Checkpoint,town_or_string,		SLE_UINT16),
  1806 	SLE_VAR(Waypoint,town_or_string,		SLE_UINT16),
  1807 	SLE_VAR(Checkpoint,deleted,						SLE_UINT8),
  1807 	SLE_VAR(Waypoint,deleted,						SLE_UINT8),
  1808 
  1808 
  1809 	SLE_CONDVAR(Checkpoint, build_date, SLE_UINT16, 3, 255),
  1809 	SLE_CONDVAR(Waypoint, build_date, SLE_UINT16, 3, 255),
  1810 	SLE_CONDVAR(Checkpoint, stat_id, SLE_UINT8, 3, 255),
  1810 	SLE_CONDVAR(Waypoint, stat_id, SLE_UINT8, 3, 255),
  1811 
  1811 
  1812 	SLE_END()
  1812 	SLE_END()
  1813 };
  1813 };
  1814 
  1814 
  1815 static void Save_CHKP()
  1815 static void Save_CHKP()
  1816 {
  1816 {
  1817 	Checkpoint *cp;
  1817 	Waypoint *cp;
  1818 	int i;
  1818 	int i;
  1819 	for(i=0,cp=_checkpoints; i!=lengthof(_checkpoints); i++,cp++) {
  1819 	for(i=0,cp=_waypoints; i!=lengthof(_waypoints); i++,cp++) {
  1820 		if (cp->xy != 0) {
  1820 		if (cp->xy != 0) {
  1821 			SlSetArrayIndex(i);
  1821 			SlSetArrayIndex(i);
  1822 			SlObject(cp, _checkpoint_desc);
  1822 			SlObject(cp, _waypoint_desc);
  1823 		}
  1823 		}
  1824 	}
  1824 	}
  1825 }
  1825 }
  1826 
  1826 
  1827 static void Load_CHKP()
  1827 static void Load_CHKP()
  1828 {
  1828 {
  1829 	int index;
  1829 	int index;
  1830 	while ((index = SlIterateArray()) != -1) {
  1830 	while ((index = SlIterateArray()) != -1) {
  1831 		SlObject(&_checkpoints[index], _checkpoint_desc);
  1831 		SlObject(&_waypoints[index], _waypoint_desc);
  1832 	}
  1832 	}
  1833 }
  1833 }
  1834 
  1834 
  1835 
  1835 
  1836 static void Save_ORDR()
  1836 static void Save_ORDR()