src/train_cmd.cpp
changeset 7989 116c8f9769af
parent 7988 6075538f6111
child 7993 76b0eb3e19c9
equal deleted inserted replaced
7988:6075538f6111 7989:116c8f9769af
   556 			v = new (v) Train();
   556 			v = new (v) Train();
   557 			v->subtype = 0;
   557 			v->subtype = 0;
   558 			SetTrainWagon(v);
   558 			SetTrainWagon(v);
   559 
   559 
   560 			if (u != NULL) {
   560 			if (u != NULL) {
   561 				u->next = v;
   561 				u->SetNext(v);
   562 			} else {
   562 			} else {
   563 				SetFreeWagon(v);
   563 				SetFreeWagon(v);
   564 				InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
   564 				InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
   565 			}
   565 			}
   566 
   566 
   634 	u->spritenum = v->spritenum + 1;
   634 	u->spritenum = v->spritenum + 1;
   635 	u->cargo_type = v->cargo_type;
   635 	u->cargo_type = v->cargo_type;
   636 	u->cargo_subtype = v->cargo_subtype;
   636 	u->cargo_subtype = v->cargo_subtype;
   637 	u->cargo_cap = v->cargo_cap;
   637 	u->cargo_cap = v->cargo_cap;
   638 	u->u.rail.railtype = v->u.rail.railtype;
   638 	u->u.rail.railtype = v->u.rail.railtype;
   639 	if (building) v->next = u;
   639 	if (building) v->SetNext(u);
   640 	u->engine_type = v->engine_type;
   640 	u->engine_type = v->engine_type;
   641 	u->build_year = v->build_year;
   641 	u->build_year = v->build_year;
   642 	if (building) v->value >>= 1;
   642 	if (building) v->value >>= 1;
   643 	u->value = v->value;
   643 	u->value = v->value;
   644 	u->cur_image = 0xAC2;
   644 	u->cur_image = 0xAC2;
   838 		return v;
   838 		return v;
   839 	}
   839 	}
   840 
   840 
   841 	Vehicle *u;
   841 	Vehicle *u;
   842 	for (u = first; GetNextVehicle(u) != v; u = GetNextVehicle(u)) {}
   842 	for (u = first; GetNextVehicle(u) != v; u = GetNextVehicle(u)) {}
   843 	GetLastEnginePart(u)->next = GetNextVehicle(v);
   843 	GetLastEnginePart(u)->SetNext(GetNextVehicle(v));
   844 	v->first = NULL; // we shouldn't point to the old first, since the vehicle isn't in that chain anymore
   844 	v->first = NULL; // we shouldn't point to the old first, since the vehicle isn't in that chain anymore
   845 	return first;
   845 	return first;
   846 }
   846 }
   847 
   847 
   848 static Vehicle *FindGoodVehiclePos(const Vehicle *src)
   848 static Vehicle *FindGoodVehiclePos(const Vehicle *src)
  1039 		if (HASBIT(p2, 0)) {
  1039 		if (HASBIT(p2, 0)) {
  1040 			/* unlink ALL wagons */
  1040 			/* unlink ALL wagons */
  1041 			if (src != src_head) {
  1041 			if (src != src_head) {
  1042 				Vehicle *v = src_head;
  1042 				Vehicle *v = src_head;
  1043 				while (GetNextVehicle(v) != src) v = GetNextVehicle(v);
  1043 				while (GetNextVehicle(v) != src) v = GetNextVehicle(v);
  1044 				GetLastEnginePart(v)->next = NULL;
  1044 				GetLastEnginePart(v)->SetNext(NULL);
  1045 			} else {
  1045 			} else {
  1046 				InvalidateWindowData(WC_VEHICLE_DEPOT, src_head->tile); // We removed a line
  1046 				InvalidateWindowData(WC_VEHICLE_DEPOT, src_head->tile); // We removed a line
  1047 				src_head = NULL;
  1047 				src_head = NULL;
  1048 			}
  1048 			}
  1049 		} else {
  1049 		} else {
  1050 			/* if moving within the same chain, dont use dst_head as it may get invalidated */
  1050 			/* if moving within the same chain, dont use dst_head as it may get invalidated */
  1051 			if (src_head == dst_head) dst_head = NULL;
  1051 			if (src_head == dst_head) dst_head = NULL;
  1052 			/* unlink single wagon from linked list */
  1052 			/* unlink single wagon from linked list */
  1053 			src_head = UnlinkWagon(src, src_head);
  1053 			src_head = UnlinkWagon(src, src_head);
  1054 			GetLastEnginePart(src)->next = NULL;
  1054 			GetLastEnginePart(src)->SetNext(NULL);
  1055 		}
  1055 		}
  1056 
  1056 
  1057 		if (dst == NULL) {
  1057 		if (dst == NULL) {
  1058 			/* We make a new line in the depot, so we know already that we invalidate the window data */
  1058 			/* We make a new line in the depot, so we know already that we invalidate the window data */
  1059 			InvalidateWindowData(WC_VEHICLE_DEPOT, src->tile);
  1059 			InvalidateWindowData(WC_VEHICLE_DEPOT, src->tile);