653 int y = TileY(tile) * TILE_SIZE | _vehicle_initial_y_fract[dir]; |
653 int y = TileY(tile) * TILE_SIZE | _vehicle_initial_y_fract[dir]; |
654 |
654 |
655 v->x_pos = x; |
655 v->x_pos = x; |
656 v->y_pos = y; |
656 v->y_pos = y; |
657 v->z_pos = GetSlopeZ(x, y); |
657 v->z_pos = GetSlopeZ(x, y); |
658 v->owner = _current_player; |
658 v->owner = _current_company; |
659 v->u.rail.track = TRACK_BIT_DEPOT; |
659 v->u.rail.track = TRACK_BIT_DEPOT; |
660 v->vehstatus = VS_HIDDEN | VS_DEFPAL; |
660 v->vehstatus = VS_HIDDEN | VS_DEFPAL; |
661 |
661 |
662 // v->subtype = 0; |
662 // v->subtype = 0; |
663 SetTrainWagon(v); |
663 SetTrainWagon(v); |
690 VehiclePositionChanged(v); |
690 VehiclePositionChanged(v); |
691 TrainConsistChanged(v->First(), false); |
691 TrainConsistChanged(v->First(), false); |
692 UpdateTrainGroupID(v->First()); |
692 UpdateTrainGroupID(v->First()); |
693 |
693 |
694 InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
694 InvalidateWindow(WC_VEHICLE_DEPOT, v->tile); |
695 if (IsLocalPlayer()) { |
695 if (IsLocalCompany()) { |
696 InvalidateAutoreplaceWindow(v->engine_type, v->group_id); // updates the replace Train window |
696 InvalidateAutoreplaceWindow(v->engine_type, v->group_id); // updates the replace Train window |
697 } |
697 } |
698 GetPlayer(_current_player)->num_engines[engine]++; |
698 GetCompany(_current_company)->num_engines[engine]++; |
699 } |
699 } |
700 } |
700 } |
701 |
701 |
702 return value; |
702 return value; |
703 } |
703 } |
757 * @param p1 engine type id |
757 * @param p1 engine type id |
758 * @param p2 bit 1 prevents any free cars from being added to the train |
758 * @param p2 bit 1 prevents any free cars from being added to the train |
759 */ |
759 */ |
760 CommandCost CmdBuildRailVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
760 CommandCost CmdBuildRailVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
761 { |
761 { |
762 /* Check if the engine-type is valid (for the player) */ |
762 /* Check if the engine-type is valid (for the company) */ |
763 if (!IsEngineBuildable(p1, VEH_TRAIN, _current_player)) return_cmd_error(STR_RAIL_VEHICLE_NOT_AVAILABLE); |
763 if (!IsEngineBuildable(p1, VEH_TRAIN, _current_company)) return_cmd_error(STR_RAIL_VEHICLE_NOT_AVAILABLE); |
764 |
764 |
765 /* Check if the train is actually being built in a depot belonging |
765 /* Check if the train is actually being built in a depot belonging |
766 * to the player. Doesn't matter if only the cost is queried */ |
766 * to the company. Doesn't matter if only the cost is queried */ |
767 if (!(flags & DC_QUERY_COST)) { |
767 if (!(flags & DC_QUERY_COST)) { |
768 if (!IsRailDepotTile(tile)) return CMD_ERROR; |
768 if (!IsRailDepotTile(tile)) return CMD_ERROR; |
769 if (!IsTileOwner(tile, _current_player)) return CMD_ERROR; |
769 if (!IsTileOwner(tile, _current_company)) return CMD_ERROR; |
770 } |
770 } |
771 |
771 |
772 const RailVehicleInfo *rvi = RailVehInfo(p1); |
772 const RailVehicleInfo *rvi = RailVehInfo(p1); |
773 |
773 |
774 if (rvi->railveh_type == RAILVEH_WAGON) return CmdBuildRailWagon(p1, tile, flags); |
774 if (rvi->railveh_type == RAILVEH_WAGON) return CmdBuildRailWagon(p1, tile, flags); |
805 |
805 |
806 v = new (v) Train(); |
806 v = new (v) Train(); |
807 v->unitnumber = unit_num; |
807 v->unitnumber = unit_num; |
808 v->direction = DiagDirToDir(dir); |
808 v->direction = DiagDirToDir(dir); |
809 v->tile = tile; |
809 v->tile = tile; |
810 v->owner = _current_player; |
810 v->owner = _current_company; |
811 v->x_pos = x; |
811 v->x_pos = x; |
812 v->y_pos = y; |
812 v->y_pos = y; |
813 v->z_pos = GetSlopeZ(x, y); |
813 v->z_pos = GetSlopeZ(x, y); |
814 // v->running_ticks = 0; |
814 // v->running_ticks = 0; |
815 v->u.rail.track = TRACK_BIT_DEPOT; |
815 v->u.rail.track = TRACK_BIT_DEPOT; |
872 } |
872 } |
873 |
873 |
874 InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); |
874 InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile); |
875 InvalidateWindowClassesData(WC_TRAINS_LIST, 0); |
875 InvalidateWindowClassesData(WC_TRAINS_LIST, 0); |
876 InvalidateWindow(WC_COMPANY, v->owner); |
876 InvalidateWindow(WC_COMPANY, v->owner); |
877 if (IsLocalPlayer()) { |
877 if (IsLocalCompany()) { |
878 InvalidateAutoreplaceWindow(v->engine_type, v->group_id); // updates the replace Train window |
878 InvalidateAutoreplaceWindow(v->engine_type, v->group_id); // updates the replace Train window |
879 } |
879 } |
880 |
880 |
881 GetPlayer(_current_player)->num_engines[p1]++; |
881 GetCompany(_current_company)->num_engines[p1]++; |
882 } |
882 } |
883 } |
883 } |
884 |
884 |
885 return value; |
885 return value; |
886 } |
886 } |
1448 |
1448 |
1449 /* Copy other important data from the front engine */ |
1449 /* Copy other important data from the front engine */ |
1450 new_f->CopyVehicleConfigAndStatistics(first); |
1450 new_f->CopyVehicleConfigAndStatistics(first); |
1451 |
1451 |
1452 /* If we deleted a window then open a new one for the 'new' train */ |
1452 /* If we deleted a window then open a new one for the 'new' train */ |
1453 if (IsLocalPlayer() && w != NULL) ShowVehicleViewWindow(new_f); |
1453 if (IsLocalCompany() && w != NULL) ShowVehicleViewWindow(new_f); |
1454 } |
1454 } |
1455 } else { |
1455 } else { |
1456 /* We are selling a free wagon, and construct a new train at the same time. |
1456 /* We are selling a free wagon, and construct a new train at the same time. |
1457 * This needs lots of extra checks (e.g. train limit), which are done by first moving |
1457 * This needs lots of extra checks (e.g. train limit), which are done by first moving |
1458 * the remaining vehicles to a new row */ |
1458 * the remaining vehicles to a new row */ |
2225 CommandCost CmdSendTrainToDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
2225 CommandCost CmdSendTrainToDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
2226 { |
2226 { |
2227 if (p2 & DEPOT_MASS_SEND) { |
2227 if (p2 & DEPOT_MASS_SEND) { |
2228 /* Mass goto depot requested */ |
2228 /* Mass goto depot requested */ |
2229 if (!ValidVLWFlags(p2 & VLW_MASK)) return CMD_ERROR; |
2229 if (!ValidVLWFlags(p2 & VLW_MASK)) return CMD_ERROR; |
2230 return SendAllVehiclesToDepot(VEH_TRAIN, flags, p2 & DEPOT_SERVICE, _current_player, (p2 & VLW_MASK), p1); |
2230 return SendAllVehiclesToDepot(VEH_TRAIN, flags, p2 & DEPOT_SERVICE, _current_company, (p2 & VLW_MASK), p1); |
2231 } |
2231 } |
2232 |
2232 |
2233 if (!IsValidVehicleID(p1)) return CMD_ERROR; |
2233 if (!IsValidVehicleID(p1)) return CMD_ERROR; |
2234 |
2234 |
2235 Vehicle *v = GetVehicle(p1); |
2235 Vehicle *v = GetVehicle(p1); |
2914 /* PF didn't find the route */ |
2914 /* PF didn't find the route */ |
2915 if (!HasBit(v->u.rail.flags, VRF_NO_PATH_TO_DESTINATION)) { |
2915 if (!HasBit(v->u.rail.flags, VRF_NO_PATH_TO_DESTINATION)) { |
2916 /* it is first time the problem occurred, set the "path not found" flag */ |
2916 /* it is first time the problem occurred, set the "path not found" flag */ |
2917 SetBit(v->u.rail.flags, VRF_NO_PATH_TO_DESTINATION); |
2917 SetBit(v->u.rail.flags, VRF_NO_PATH_TO_DESTINATION); |
2918 /* and notify user about the event */ |
2918 /* and notify user about the event */ |
2919 if (_settings_client.gui.lost_train_warn && v->owner == _local_player) { |
2919 if (_settings_client.gui.lost_train_warn && v->owner == _local_company) { |
2920 SetDParam(0, v->unitnumber); |
2920 SetDParam(0, v->unitnumber); |
2921 AddNewsItem( |
2921 AddNewsItem( |
2922 STR_TRAIN_IS_LOST, |
2922 STR_TRAIN_IS_LOST, |
2923 NS_ADVICE, |
2923 NS_ADVICE, |
2924 v->index, |
2924 v->index, |
3270 if (!(st->had_vehicle_of_type & HVOT_TRAIN)) { |
3270 if (!(st->had_vehicle_of_type & HVOT_TRAIN)) { |
3271 st->had_vehicle_of_type |= HVOT_TRAIN; |
3271 st->had_vehicle_of_type |= HVOT_TRAIN; |
3272 SetDParam(0, st->index); |
3272 SetDParam(0, st->index); |
3273 AddNewsItem( |
3273 AddNewsItem( |
3274 STR_8801_CITIZENS_CELEBRATE_FIRST, |
3274 STR_8801_CITIZENS_CELEBRATE_FIRST, |
3275 v->owner == _local_player ? NS_ARRIVAL_PLAYER : NS_ARRIVAL_OTHER, |
3275 v->owner == _local_company ? NS_ARRIVAL_COMPANY : NS_ARRIVAL_OTHER, |
3276 v->index, |
3276 v->index, |
3277 st->index |
3277 st->index |
3278 ); |
3278 ); |
3279 } |
3279 } |
3280 |
3280 |
4252 /* Still stuck. */ |
4252 /* Still stuck. */ |
4253 if (turn_around) ReverseTrainDirection(v); |
4253 if (turn_around) ReverseTrainDirection(v); |
4254 |
4254 |
4255 if (HasBit(v->u.rail.flags, VRF_TRAIN_STUCK) && v->load_unload_time_rem > 2 * _settings_game.pf.wait_for_pbs_path * DAY_TICKS) { |
4255 if (HasBit(v->u.rail.flags, VRF_TRAIN_STUCK) && v->load_unload_time_rem > 2 * _settings_game.pf.wait_for_pbs_path * DAY_TICKS) { |
4256 /* Show message to player. */ |
4256 /* Show message to player. */ |
4257 if (_settings_client.gui.lost_train_warn && v->owner == _local_player) { |
4257 if (_settings_client.gui.lost_train_warn && v->owner == _local_company) { |
4258 SetDParam(0, v->unitnumber); |
4258 SetDParam(0, v->unitnumber); |
4259 AddNewsItem( |
4259 AddNewsItem( |
4260 STR_TRAIN_IS_STUCK, |
4260 STR_TRAIN_IS_STUCK, |
4261 NS_ADVICE, |
4261 NS_ADVICE, |
4262 v->index, |
4262 v->index, |
4399 CommandCost cost(EXPENSES_TRAIN_RUN, this->GetRunningCost() * this->running_ticks / (364 * DAY_TICKS)); |
4399 CommandCost cost(EXPENSES_TRAIN_RUN, this->GetRunningCost() * this->running_ticks / (364 * DAY_TICKS)); |
4400 |
4400 |
4401 this->profit_this_year -= cost.GetCost(); |
4401 this->profit_this_year -= cost.GetCost(); |
4402 this->running_ticks = 0; |
4402 this->running_ticks = 0; |
4403 |
4403 |
4404 SubtractMoneyFromPlayerFract(this->owner, cost); |
4404 SubtractMoneyFromCompanyFract(this->owner, cost); |
4405 |
4405 |
4406 InvalidateWindow(WC_VEHICLE_DETAILS, this->index); |
4406 InvalidateWindow(WC_VEHICLE_DETAILS, this->index); |
4407 InvalidateWindowClasses(WC_TRAINS_LIST); |
4407 InvalidateWindowClasses(WC_TRAINS_LIST); |
4408 } |
4408 } |
4409 } else if (IsTrainEngine(this)) { |
4409 } else if (IsTrainEngine(this)) { |
4417 Vehicle *v; |
4417 Vehicle *v; |
4418 |
4418 |
4419 FOR_ALL_VEHICLES(v) { |
4419 FOR_ALL_VEHICLES(v) { |
4420 if (v->type == VEH_TRAIN && IsFrontEngine(v)) { |
4420 if (v->type == VEH_TRAIN && IsFrontEngine(v)) { |
4421 /* show warning if train is not generating enough income last 2 years (corresponds to a red icon in the vehicle list) */ |
4421 /* show warning if train is not generating enough income last 2 years (corresponds to a red icon in the vehicle list) */ |
4422 if (_settings_client.gui.train_income_warn && v->owner == _local_player && v->age >= 730 && v->GetDisplayProfitThisYear() < 0) { |
4422 if (_settings_client.gui.train_income_warn && v->owner == _local_company && v->age >= 730 && v->GetDisplayProfitThisYear() < 0) { |
4423 SetDParam(1, v->GetDisplayProfitThisYear()); |
4423 SetDParam(1, v->GetDisplayProfitThisYear()); |
4424 SetDParam(0, v->unitnumber); |
4424 SetDParam(0, v->unitnumber); |
4425 AddNewsItem( |
4425 AddNewsItem( |
4426 STR_TRAIN_IS_UNPROFITABLE, |
4426 STR_TRAIN_IS_UNPROFITABLE, |
4427 NS_ADVICE, |
4427 NS_ADVICE, |