diff --git a/src/departures.cpp b/src/departures.cpp index 733f32a423..cf2d6d2516 100644 --- a/src/departures.cpp +++ b/src/departures.cpp @@ -192,7 +192,7 @@ static bool VehicleSetNextDepartureTime(Ticks *previous_departure, Ticks *waitin static void ScheduledDispatchDepartureLocalFix(DepartureList *departure_list) { - /* Seperate departure by each shared order group */ + /* Separate departure by each shared order group */ btree::btree_map> separated_departure; for (Departure* departure : *departure_list) { separated_departure[departure->vehicle->orders->index].push_back(departure); diff --git a/src/ground_vehicle.cpp b/src/ground_vehicle.cpp index 29fe849627..abb3068193 100644 --- a/src/ground_vehicle.cpp +++ b/src/ground_vehicle.cpp @@ -252,7 +252,7 @@ GroundVehicleAcceleration GroundVehicle::GetAcceleration() * This yields a number x on a 0-1 scale, but shifted 16 bits to the left. * We then calculate 64 + 128x, clamped to 0-255, but still shifted 16 bits to the left. * Then we apply a correction for multiengine trains, and in the end we shift it 16 bits to the right to get a 0-255 number. - * @note A seperate correction for multiheaded engines is done in CheckVehicleBreakdown. We can't do that here because it would affect the whole consist. + * @note A separate correction for multiheaded engines is done in CheckVehicleBreakdown. We can't do that here because it would affect the whole consist. */ uint64_t breakdown_factor = (uint64_t)abs(resistance) * (uint64_t)(this->cur_speed << 16); breakdown_factor /= (std::max(force, (int64_t)100) * this->gcache.cached_max_track_speed); diff --git a/src/order_gui.cpp b/src/order_gui.cpp index 077a106866..ddcbea8b05 100644 --- a/src/order_gui.cpp +++ b/src/order_gui.cpp @@ -1017,7 +1017,7 @@ void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int SetDParam(1, order->GetConditionSkipToOrder() + 1); const OrderConditionVariable ocv = order->GetConditionVariable(); - /* handle some non-ordinary cases seperately */ + /* handle some non-ordinary cases separately */ if (ocv == OCV_UNCONDITIONALLY) { SetDParam(0, STR_ORDER_CONDITIONAL_UNCONDITIONAL); } else if (ocv == OCV_PERCENT) { diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp index 3fedf2894e..fba44fd7f4 100644 --- a/src/ship_cmd.cpp +++ b/src/ship_cmd.cpp @@ -1123,7 +1123,7 @@ static void ShipController(Ship *v) /* Ship is back on the bridge head, we need to consume its path * cache entry here as we didn't have to choose a ship track. */ - if (!v->cached_path.empty()) v->cached_path.pop_front(); + if (!v->cached_path.empty()) v->cached_path.pop_front(); } /* update image of ship, as well as delta XY */ diff --git a/src/sl/extended_ver_sl.h b/src/sl/extended_ver_sl.h index a757d1b4a7..ce2e7b7be7 100644 --- a/src/sl/extended_ver_sl.h +++ b/src/sl/extended_ver_sl.h @@ -280,7 +280,7 @@ struct SlxiSubChunkInfo { const char *name; ///< feature name, this *IS* saved, so must be globally unique SlxiSubChunkSaveProc *save_proc; ///< save procedure of the sub chunk, this may be nullptr in which case no extra chunk data is saved SlxiSubChunkLoadProc *load_proc; ///< load procedure of the sub chunk, this may be nullptr in which case the extra chunk data must be missing or of 0 length - const char *chunk_list; ///< this is a list of chunks that this feature uses, which should be written to the savegame, this must be a comma-seperated list of 4-character IDs, with no spaces, or nullptr + const char *chunk_list; ///< this is a list of chunks that this feature uses, which should be written to the savegame, this must be a comma-separated list of 4-character IDs, with no spaces, or nullptr }; void SlXvResetState(); diff --git a/src/tracerestrict.cpp b/src/tracerestrict.cpp index c4428dd3a7..01d7d7e49b 100644 --- a/src/tracerestrict.cpp +++ b/src/tracerestrict.cpp @@ -109,10 +109,10 @@ void ClearTraceRestrictMapping() { * Elif/orif/else may modify the stack top */ enum TraceRestrictCondStackFlags { - TRCSF_DONE_IF = 1<<0, ///< The if/elif/else is "done", future elif/else branches will not be executed - TRCSF_SEEN_ELSE = 1<<1, ///< An else branch has been seen already, error if another is seen afterwards - TRCSF_ACTIVE = 1<<2, ///< The condition is currently active - TRCSF_PARENT_INACTIVE = 1<<3, ///< The parent condition is not active, thus this condition is also not active + TRCSF_DONE_IF = 1 << 0, ///< The if/elif/else is "done", future elif/else branches will not be executed + TRCSF_SEEN_ELSE = 1 << 1, ///< An else branch has been seen already, error if another is seen afterwards + TRCSF_ACTIVE = 1 << 2, ///< The condition is currently active + TRCSF_PARENT_INACTIVE = 1 << 3, ///< The parent condition is not active, thus this condition is also not active }; DECLARE_ENUM_AS_BIT_SET(TraceRestrictCondStackFlags) @@ -124,7 +124,7 @@ static void HandleCondition(std::vector &condstack, if (condflags & TRCF_OR) { assert(!condstack.empty()); if (condstack.back() & TRCSF_ACTIVE) { - // leave TRCSF_ACTIVE set + /* Leave TRCSF_ACTIVE set */ return; } } @@ -137,7 +137,7 @@ static void HandleCondition(std::vector &condstack, } } else { if (!condstack.empty() && !(condstack.back() & TRCSF_ACTIVE)) { - //this is a 'nested if', the 'parent if' is not active + /* This is a 'nested if', the 'parent if' is not active */ condstack.push_back(TRCSF_PARENT_INACTIVE); return; } @@ -202,7 +202,7 @@ static bool TestOrderCondition(const Order *order, TraceRestrictItem item) { bool result = false; - if (order) { + if (order != nullptr) { DestinationID condvalue = GetTraceRestrictValue(item); switch (static_cast(GetTraceRestrictAuxField(item))) { case TROCAF_STATION: @@ -242,7 +242,7 @@ static bool TestStationCondition(StationID station, TraceRestrictItem item) */ void TraceRestrictProgram::Execute(const Train* v, const TraceRestrictProgramInput &input, TraceRestrictProgramResult& out) const { - /* static to avoid needing to re-alloc/resize on each execution */ + /* Static to avoid needing to re-alloc/resize on each execution */ static std::vector condstack; condstack.clear(); @@ -264,12 +264,12 @@ void TraceRestrictProgram::Execute(const Train* v, const TraceRestrictProgramInp if (type == TRIT_COND_ENDIF) { assert(!condstack.empty()); if (condflags & TRCF_ELSE) { - // else + /* Else */ assert(!(condstack.back() & TRCSF_SEEN_ELSE)); HandleCondition(condstack, condflags, true); condstack.back() |= TRCSF_SEEN_ELSE; } else { - // end if + /* End if */ condstack.pop_back(); } } else { @@ -357,7 +357,7 @@ void TraceRestrictProgram::Execute(const Train* v, const TraceRestrictProgramInp } case TRIT_COND_PBS_ENTRY_SIGNAL: { - // TRIT_COND_PBS_ENTRY_SIGNAL value type uses the next slot + /* TRIT_COND_PBS_ENTRY_SIGNAL value type uses the next slot */ i++; TraceRestrictPBSEntrySignalAuxField mode = static_cast(GetTraceRestrictAuxField(item)); assert(mode == TRPESAF_VEH_POS || mode == TRPESAF_RES_END || mode == TRPESAF_RES_END_TILE); @@ -388,17 +388,17 @@ void TraceRestrictProgram::Execute(const Train* v, const TraceRestrictProgramInp } case TRIT_COND_SLOT_OCCUPANCY: { - // TRIT_COND_SLOT_OCCUPANCY value type uses the next slot + /* TRIT_COND_SLOT_OCCUPANCY value type uses the next slot */ i++; uint32_t value = this->items[i]; const TraceRestrictSlot *slot = TraceRestrictSlot::GetIfValid(GetTraceRestrictValue(item)); switch (static_cast(GetTraceRestrictAuxField(item))) { case TRSOCAF_OCCUPANTS: - result = TestCondition(slot != nullptr ? (uint)slot->occupants.size() : 0, condop, value); + result = TestCondition(slot != nullptr ? static_cast(slot->occupants.size()) : 0, condop, value); break; case TRSOCAF_REMAINING: - result = TestCondition(slot != nullptr ? slot->max_occupancy - (uint)slot->occupants.size() : 0, condop, value); + result = TestCondition(slot != nullptr ? slot->max_occupancy - static_cast(slot->occupants.size()) : 0, condop, value); break; default: @@ -537,7 +537,7 @@ void TraceRestrictProgram::Execute(const Train* v, const TraceRestrictProgramInp } case TRIT_COND_COUNTER_VALUE: { - // TRVT_COUNTER_INDEX_INT value type uses the next slot + /* TRVT_COUNTER_INDEX_INT value type uses the next slot */ i++; uint32_t value = this->items[i]; const TraceRestrictCounter *ctr = TraceRestrictCounter::GetIfValid(GetTraceRestrictValue(item)); @@ -546,7 +546,7 @@ void TraceRestrictProgram::Execute(const Train* v, const TraceRestrictProgramInp } case TRIT_COND_TIME_DATE_VALUE: { - // TRVT_TIME_DATE_INT value type uses the next slot + /* TRVT_TIME_DATE_INT value type uses the next slot */ i++; uint32_t value = this->items[i]; result = TestCondition(GetTraceRestrictTimeDateValue(static_cast(GetTraceRestrictValue(item))), condop, value); @@ -628,7 +628,7 @@ void TraceRestrictProgram::Execute(const Train* v, const TraceRestrictProgramInp } case TRIT_COND_RESERVATION_THROUGH: { - // TRIT_COND_RESERVATION_THROUGH value type uses the next slot + /* TRIT_COND_RESERVATION_THROUGH value type uses the next slot */ i++; uint32_t test_tile = this->items[i]; result = TestBinaryConditionCommon(item, TrainReservationPassesThroughTile(v, test_tile)); @@ -834,7 +834,7 @@ void TraceRestrictProgram::Execute(const Train* v, const TraceRestrictProgramInp break; case TRIT_COUNTER: { - // TRVT_COUNTER_INDEX_INT value type uses the next slot + /* TRVT_COUNTER_INDEX_INT value type uses the next slot */ i++; uint32_t value = this->items[i]; if (!(input.permitted_slot_operations & TRPISP_CHANGE_COUNTER)) break; @@ -929,7 +929,7 @@ void TraceRestrictProgram::IncrementRefCount(TraceRestrictRefId ref_id) this->ref_ids.ptr_ref_ids.buffer = ptr; this->ref_ids.ptr_ref_ids.elem_capacity = 8; } else if (this->refcount == this->ref_ids.ptr_ref_ids.elem_capacity) { - // grow buffer + /* Grow buffer */ this->ref_ids.ptr_ref_ids.elem_capacity *= 2; this->ref_ids.ptr_ref_ids.buffer = ReallocT(this->ref_ids.ptr_ref_ids.buffer, this->ref_ids.ptr_ref_ids.elem_capacity); } @@ -979,7 +979,7 @@ void TraceRestrictProgram::DecrementRefCount(TraceRestrictRefId ref_id) { * and that all instructions have a known type, at present */ CommandCost TraceRestrictProgram::Validate(const std::vector &items, TraceRestrictProgramActionsUsedFlags &actions_used_flags) { - // static to avoid needing to re-alloc/resize on each execution + /* Static to avoid needing to re-alloc/resize on each execution */ static std::vector condstack; condstack.clear(); actions_used_flags = TRPAUF_NONE; @@ -996,7 +996,7 @@ CommandCost TraceRestrictProgram::Validate(const std::vector auto validation_error = [i](StringID str) -> CommandCost { CommandCost result(str); - result.SetResultData((uint)i); + result.SetResultData(static_cast(i)); return result; }; @@ -1004,11 +1004,11 @@ CommandCost TraceRestrictProgram::Validate(const std::vector return validation_error(STR_TRACE_RESTRICT_ERROR_VALIDATE_UNKNOWN_INSTRUCTION); }; - // check multi-word instructions + /* Check multi-word instructions */ if (IsTraceRestrictDoubleItem(item)) { i++; if (i >= size) { - return validation_error(STR_TRACE_RESTRICT_ERROR_OFFSET_TOO_LARGE); // instruction ran off end + return validation_error(STR_TRACE_RESTRICT_ERROR_OFFSET_TOO_LARGE); // Instruction ran off end } } @@ -1017,17 +1017,17 @@ CommandCost TraceRestrictProgram::Validate(const std::vector if (type == TRIT_COND_ENDIF) { if (condstack.empty()) { - return validation_error(STR_TRACE_RESTRICT_ERROR_VALIDATE_NO_IF); // else/endif with no starting if + return validation_error(STR_TRACE_RESTRICT_ERROR_VALIDATE_NO_IF); // Else/endif with no starting if } if (condflags & TRCF_ELSE) { - // else + /* Else */ if (condstack.back() & TRCSF_SEEN_ELSE) { return validation_error(STR_TRACE_RESTRICT_ERROR_VALIDATE_DUP_ELSE); // Two else clauses } HandleCondition(condstack, condflags, true); condstack.back() |= TRCSF_SEEN_ELSE; } else { - // end if + /* End if */ condstack.pop_back(); } } else { @@ -1036,7 +1036,7 @@ CommandCost TraceRestrictProgram::Validate(const std::vector return validation_error(STR_TRACE_RESTRICT_ERROR_VALIDATE_ELIF_NO_IF); // Pre-empt assertions in HandleCondition } if (condstack.back() & TRCSF_SEEN_ELSE) { - return validation_error(STR_TRACE_RESTRICT_ERROR_VALIDATE_DUP_ELSE); // else clause followed by elif/orif + return validation_error(STR_TRACE_RESTRICT_ERROR_VALIDATE_DUP_ELSE); // Else clause followed by elif/orif } } HandleCondition(condstack, condflags, true); @@ -1077,7 +1077,7 @@ CommandCost TraceRestrictProgram::Validate(const std::vector } }; - /* Validation action instruction */ + /* Validate condition type */ switch (GetTraceRestrictType(item)) { case TRIT_COND_ENDIF: case TRIT_COND_UNDEFINED: @@ -1642,7 +1642,7 @@ void SetTraceRestrictTypeAndNormalise(TraceRestrictItem &item, TraceRestrictItem } } if (GetTraceRestrictType(item) == TRIT_COND_LAST_STATION && GetTraceRestrictAuxField(item) != TROCAF_STATION) { - // if changing type from another order type to last visited station, reset value if not currently a station + /* If changing type from another order type to last visited station, reset value if not currently a station */ SetTraceRestrictValueDefault(item, TRVT_ORDER); } } @@ -1653,12 +1653,12 @@ void SetTraceRestrictTypeAndNormalise(TraceRestrictItem &item, TraceRestrictItem */ void TraceRestrictSetIsSignalRestrictedBit(TileIndex t) { - // First mapping for this tile, or later + /* First mapping for this tile, or later */ TraceRestrictMapping::iterator lower_bound = _tracerestrictprogram_mapping.lower_bound(MakeTraceRestrictRefId(t, static_cast(0))); bool found = (lower_bound != _tracerestrictprogram_mapping.end()) && (GetTraceRestrictRefIdTileIndex(lower_bound->first) == t); - // If iterators are the same, there are no mappings for this tile + /* If iterators are the same, there are no mappings for this tile */ switch (GetTileType(t)) { case MP_RAILWAY: SetRestrictedSignal(t, found); @@ -1683,8 +1683,8 @@ void TraceRestrictCreateProgramMapping(TraceRestrictRefId ref, TraceRestrictProg _tracerestrictprogram_mapping.insert(std::make_pair(ref, TraceRestrictMappingItem(prog->index))); if (!insert_result.second) { - // value was not inserted, there is an existing mapping - // unref the existing mapping before updating it + /* Value was not inserted, there is an existing mapping. + * Unref the existing mapping before updating it. */ _tracerestrictprogram_pool.Get(insert_result.first->second.program_id)->DecrementRefCount(ref); insert_result.first->second = prog->index; } @@ -1705,13 +1705,13 @@ bool TraceRestrictRemoveProgramMapping(TraceRestrictRefId ref) { TraceRestrictMapping::iterator iter = _tracerestrictprogram_mapping.find(ref); if (iter != _tracerestrictprogram_mapping.end()) { - // Found + /* Found */ TraceRestrictProgram *prog = _tracerestrictprogram_pool.Get(iter->second.program_id); bool update_reserve_through = (prog->actions_used_flags & TRPAUF_RESERVE_THROUGH_ALWAYS); - // check to see if another mapping needs to be removed as well - // do this before decrementing the refcount + /* Check to see if another mapping needs to be removed as well, + * do this before decrementing the refcount */ bool remove_other_mapping = prog->refcount == 2 && prog->items.empty(); prog->DecrementRefCount(ref); @@ -1774,22 +1774,22 @@ void TraceRestrictCheckRefreshSingleSignal(const TraceRestrictProgram *prog, Tra */ TraceRestrictProgram *GetTraceRestrictProgram(TraceRestrictRefId ref, bool create_new) { - // Optimise for lookup, creating doesn't have to be that fast + /* Optimise for lookup, creating doesn't have to be that fast */ TraceRestrictMapping::iterator iter = _tracerestrictprogram_mapping.find(ref); if (iter != _tracerestrictprogram_mapping.end()) { - // Found + /* Found */ return _tracerestrictprogram_pool.Get(iter->second.program_id); } else if (create_new) { - // Not found + /* Not found */ - // Create new pool item + /* Create new pool item */ if (!TraceRestrictProgram::CanAllocateItem()) { return nullptr; } TraceRestrictProgram *prog = new TraceRestrictProgram(); - // Create new mapping to pool item + /* Create new mapping to pool item */ TraceRestrictCreateProgramMapping(ref, prog); return prog; } else { @@ -1803,7 +1803,7 @@ TraceRestrictProgram *GetTraceRestrictProgram(TraceRestrictRefId ref, bool creat */ TraceRestrictProgram *GetFirstTraceRestrictProgramOnTile(TileIndex t) { - // First mapping for this tile, or later + /* First mapping for this tile, or later */ TraceRestrictMapping::iterator lower_bound = _tracerestrictprogram_mapping.lower_bound(MakeTraceRestrictRefId(t, static_cast(0))); if ((lower_bound != _tracerestrictprogram_mapping.end()) && (GetTraceRestrictRefIdTileIndex(lower_bound->first) == t)) { @@ -1842,7 +1842,7 @@ void TraceRestrictDoCommandP(TileIndex tile, Track track, TraceRestrictDoCommand */ static CommandCost TraceRestrictCheckTileIsUsable(TileIndex tile, Track track) { - // Check that there actually is a signal here + /* Check that there actually is a signal here */ switch (GetTileType(tile)) { case MP_RAILWAY: if (!IsPlainRailTile(tile) || !HasTrack(tile, track)) { @@ -1866,7 +1866,7 @@ static CommandCost TraceRestrictCheckTileIsUsable(TileIndex tile, Track track) return_cmd_error(STR_ERROR_THERE_IS_NO_RAILROAD_TRACK); } - // Check tile ownership, do this afterwards to avoid tripping up on house/industry tiles + /* Check tile ownership, do this afterwards to avoid tripping up on house/industry tiles */ CommandCost ret = CheckTileOwnership(tile); if (ret.Failed()) { return ret; @@ -1916,10 +1916,10 @@ CommandCost TraceRestrictProgramRemoveItemAt(std::vector &ite bool remove_whole_block = false; if (GetTraceRestrictCondFlags(old_item) == 0) { if (GetTraceRestrictType(old_item) == TRIT_COND_ENDIF) { - // this is an end if, can't remove these + /* This is an end if, can't remove these */ return_cmd_error(STR_TRACE_RESTRICT_ERROR_CAN_T_REMOVE_ENDIF); } else { - // this is an opening if + /* This is an opening if */ remove_whole_block = true; } } @@ -1928,42 +1928,42 @@ CommandCost TraceRestrictProgramRemoveItemAt(std::vector &ite std::vector::iterator remove_start = TraceRestrictProgram::InstructionAt(items, offset); std::vector::iterator remove_end = InstructionIteratorNext(remove_start); - // iterate until matching end block found + /* Iterate until matching end block found */ for (; remove_end != items.end(); InstructionIteratorAdvance(remove_end)) { TraceRestrictItem current_item = *remove_end; if (IsTraceRestrictConditional(current_item)) { if (GetTraceRestrictCondFlags(current_item) == 0) { if (GetTraceRestrictType(current_item) == TRIT_COND_ENDIF) { - // this is an end if + /* This is an end if */ recursion_depth--; if (recursion_depth == 0) { if (remove_whole_block) { if (shallow_mode) { - // must erase endif first, as it is later in the vector + /* Must erase endif first, as it is later in the vector */ items.erase(remove_end, InstructionIteratorNext(remove_end)); } else { - // inclusively remove up to here + /* Inclusively remove up to here */ InstructionIteratorAdvance(remove_end); } break; } else { - // exclusively remove up to here + /* Exclusively remove up to here */ break; } } } else { - // this is an opening if + /* This is an opening if */ recursion_depth++; } } else { - // this is an else/or type block + /* This is an else/or type block */ if (recursion_depth == 1 && !remove_whole_block) { - // exclusively remove up to here + /* Exclusively remove up to here */ recursion_depth = 0; break; } if (recursion_depth == 1 && remove_whole_block && shallow_mode) { - // shallow-removing whole if block, and it contains an else/or if, bail out + /* Shallow-removing whole if block, and it contains an else/or if, bail out */ return_cmd_error(STR_TRACE_RESTRICT_ERROR_CAN_T_SHALLOW_REMOVE_IF_ELIF); } } @@ -1990,7 +1990,7 @@ static CommandCost AdvanceItemEndIteratorForBlock(const std::vectoritems.size(); + if (prog != nullptr) offset_limit_exclusive += static_cast(prog->items.size()); if (offset >= offset_limit_exclusive) { return_cmd_error(STR_TRACE_RESTRICT_ERROR_OFFSET_TOO_LARGE); } - // copy program + /* Copy program */ std::vector items; - if (prog) items = prog->items; + if (prog != nullptr) items = prog->items; switch (type) { case TRDCT_INSERT_ITEM: @@ -2144,7 +2144,7 @@ CommandCost CmdProgramSignalTraceRestrict(TileIndex tile, DoCommandFlag flags, u if (IsTraceRestrictConditional(item) && GetTraceRestrictCondFlags(item) == 0 && GetTraceRestrictType(item) != TRIT_COND_ENDIF) { - // this is an opening if block, insert a corresponding end if + /* This is an opening if block, insert a corresponding end if */ TraceRestrictItem endif_item = 0; SetTraceRestrictType(endif_item, TRIT_COND_ENDIF); items.insert(TraceRestrictProgram::InstructionAt(items, offset) + 1, endif_item); @@ -2211,25 +2211,25 @@ CommandCost CmdProgramSignalTraceRestrict(TileIndex tile, DoCommandFlag flags, u } if (flags & DC_EXEC) { - assert(prog); + assert(prog != nullptr); size_t old_size = prog->items.size(); TraceRestrictProgramActionsUsedFlags old_actions_used_flags = prog->actions_used_flags; - // move in modified program + /* Move in modified program */ prog->items.swap(items); prog->actions_used_flags = actions_used_flags; if (prog->items.size() == 0 && prog->refcount == 1) { - // program is empty, and this tile is the only reference to it - // so delete it, as it's redundant + /* Program is empty, and this tile is the only reference to it, + * so delete it, as it's redundant */ TraceRestrictCheckRefreshSingleSignal(prog, MakeTraceRestrictRefId(tile, track), old_actions_used_flags); TraceRestrictRemoveProgramMapping(MakeTraceRestrictRefId(tile, track)); } else { TraceRestrictCheckRefreshSignals(prog, old_size, old_actions_used_flags); } - // update windows + /* Update windows */ InvalidateWindowClassesData(WC_TRACE_RESTRICT); } @@ -2303,10 +2303,10 @@ CommandCost CmdProgramSignalTraceRestrictProgMgmt(TileIndex tile, DoCommandFlag TraceRestrictRemoveProgramMapping(self); TraceRestrictProgram *source_prog = GetTraceRestrictProgram(source, false); - if (source_prog && !source_prog->items.empty()) { + if (source_prog != nullptr && !source_prog->items.empty()) { TraceRestrictProgram *prog = GetTraceRestrictProgram(self, true); - if (!prog) { - // allocation failed + if (prog == nullptr) { + /* Allocation failed */ return CMD_ERROR; } prog->items = source_prog->items; // copy @@ -2319,10 +2319,10 @@ CommandCost CmdProgramSignalTraceRestrictProgMgmt(TileIndex tile, DoCommandFlag case TRDCT_PROG_COPY_APPEND: { TraceRestrictProgram *source_prog = GetTraceRestrictProgram(source, false); - if (source_prog && !source_prog->items.empty()) { + if (source_prog != nullptr && !source_prog->items.empty()) { TraceRestrictProgram *prog = GetTraceRestrictProgram(self, true); - if (!prog) { - // allocation failed + if (prog == nullptr) { + /* Allocation failed */ return CMD_ERROR; } @@ -2342,8 +2342,8 @@ CommandCost CmdProgramSignalTraceRestrictProgMgmt(TileIndex tile, DoCommandFlag case TRDCT_PROG_SHARE_IF_UNMAPPED: { TraceRestrictRemoveProgramMapping(self); TraceRestrictProgram *source_prog = GetTraceRestrictProgram(source, true); - if (!source_prog) { - // allocation failed + if (source_prog == nullptr) { + /* Allocation failed */ return CMD_ERROR; } @@ -2355,18 +2355,18 @@ CommandCost CmdProgramSignalTraceRestrictProgMgmt(TileIndex tile, DoCommandFlag case TRDCT_PROG_UNSHARE: { std::vector items; TraceRestrictProgram *prog = GetTraceRestrictProgram(self, false); - if (prog) { - // copy program into temporary + if (prog != nullptr) { + /* Copy program into temporary */ items = prog->items; } - // remove old program + /* Remove old program */ TraceRestrictRemoveProgramMapping(self); - if (items.size()) { - // if prog is non-empty, create new program and move temporary in + if (items.size() > 0) { + /* If prog is non-empty, create new program and move temporary in */ TraceRestrictProgram *new_prog = GetTraceRestrictProgram(self, true); - if (!new_prog) { - // allocation failed + if (new_prog == nullptr) { + /* Allocation failed */ return CMD_ERROR; } @@ -2386,7 +2386,7 @@ CommandCost CmdProgramSignalTraceRestrictProgMgmt(TileIndex tile, DoCommandFlag return CMD_ERROR; } - // update windows + /* Update windows */ InvalidateWindowClassesData(WC_TRACE_RESTRICT); return CommandCost(); @@ -2466,7 +2466,7 @@ void TraceRestrictRemoveDestinationID(TraceRestrictOrderCondAuxField type, uint1 } } - // update windows + /* Update windows */ InvalidateWindowClassesData(WC_TRACE_RESTRICT); } @@ -2486,7 +2486,7 @@ void TraceRestrictRemoveGroupID(GroupID index) } } - // update windows + /* Update windows */ InvalidateWindowClassesData(WC_TRACE_RESTRICT); } @@ -2529,7 +2529,7 @@ void TraceRestrictUpdateCompanyID(CompanyID old_company, CompanyID new_company) } } - // update windows + /* Update windows */ InvalidateWindowClassesData(WC_TRACE_RESTRICT); InvalidateWindowClassesData(WC_TRACE_RESTRICT_SLOTS); InvalidateWindowClassesData(WC_TRACE_RESTRICT_COUNTERS); @@ -2870,7 +2870,7 @@ void TraceRestrictRemoveSlotID(TraceRestrictSlotID index) } } - // update windows + /* Update windows */ InvalidateWindowClassesData(WC_TRACE_RESTRICT); if (changed_order) { InvalidateWindowClassesData(WC_VEHICLE_ORDERS); @@ -2920,7 +2920,7 @@ CommandCost CmdCreateTraceRestrictSlot(TileIndex tile, DoCommandFlag flags, uint TraceRestrictSlot *slot = new TraceRestrictSlot(_current_company, vehtype); slot->name = text; - // update windows + /* Update windows */ InvalidateWindowClassesData(WC_TRACE_RESTRICT); InvalidateWindowClassesData(WC_TRACE_RESTRICT_SLOTS); } @@ -2945,7 +2945,7 @@ CommandCost CmdDeleteTraceRestrictSlot(TileIndex tile, DoCommandFlag flags, uint if (slot == nullptr || slot->owner != _current_company) return CMD_ERROR; if (flags & DC_EXEC) { - /* notify tracerestrict that group is about to be deleted */ + /* Notify tracerestrict that group is about to be deleted */ TraceRestrictRemoveSlotID(slot->index); delete slot; @@ -2997,7 +2997,7 @@ CommandCost CmdAlterTraceRestrictSlot(TileIndex tile, DoCommandFlag flags, uint3 } if (flags & DC_EXEC) { - // update windows + /* Update windows */ InvalidateWindowClassesData(WC_TRACE_RESTRICT); InvalidateWindowClassesData(WC_TRACE_RESTRICT_SLOTS); InvalidateWindowClassesData(WC_VEHICLE_ORDERS); @@ -3127,7 +3127,7 @@ void TraceRestrictRemoveCounterID(TraceRestrictCounterID index) } } - // update windows + /* Update windows */ InvalidateWindowClassesData(WC_TRACE_RESTRICT); if (changed_order) { InvalidateWindowClassesData(WC_VEHICLE_ORDERS); @@ -3165,7 +3165,7 @@ CommandCost CmdCreateTraceRestrictCounter(TileIndex tile, DoCommandFlag flags, u TraceRestrictCounter *ctr = new TraceRestrictCounter(_current_company); ctr->name = text; - // update windows + /* Update windows */ InvalidateWindowClassesData(WC_TRACE_RESTRICT); InvalidateWindowClassesData(WC_TRACE_RESTRICT_COUNTERS); } @@ -3190,7 +3190,7 @@ CommandCost CmdDeleteTraceRestrictCounter(TileIndex tile, DoCommandFlag flags, u if (ctr == nullptr || ctr->owner != _current_company) return CMD_ERROR; if (flags & DC_EXEC) { - /* notify tracerestrict that counter is about to be deleted */ + /* Notify tracerestrict that counter is about to be deleted */ TraceRestrictRemoveCounterID(ctr->index); delete ctr; @@ -3241,7 +3241,7 @@ CommandCost CmdAlterTraceRestrictCounter(TileIndex tile, DoCommandFlag flags, ui } if (flags & DC_EXEC) { - // update windows + /* Update windows */ InvalidateWindowClassesData(WC_TRACE_RESTRICT); InvalidateWindowClassesData(WC_TRACE_RESTRICT_COUNTERS); InvalidateWindowClassesData(WC_VEHICLE_ORDERS); diff --git a/src/tracerestrict.h b/src/tracerestrict.h index 802ab7c7d3..a536b26aa0 100644 --- a/src/tracerestrict.h +++ b/src/tracerestrict.h @@ -601,7 +601,7 @@ private: TraceRestrictRefId inline_ref_ids[4]; ptr_buffer ptr_ref_ids; - // Actual construction/destruction done by struct TraceRestrictProgram + /* Actual construction/destruction done by struct TraceRestrictProgram */ refid_list_union() {} ~refid_list_union() {} }; diff --git a/src/tracerestrict_gui.cpp b/src/tracerestrict_gui.cpp index ec344e6a1c..ec90d0da3b 100644 --- a/src/tracerestrict_gui.cpp +++ b/src/tracerestrict_gui.cpp @@ -103,25 +103,25 @@ enum TraceRestrictWindowWidgets { /** Selection mappings for NWID_SELECTION selectors */ enum PanelWidgets { - // Left 2 + /* Left 2 */ DPL2_TYPE = 0, DPL2_CONDFLAGS, DPL2_BLANK, - // Left + /* Left */ DPL_TYPE = 0, DPL_COUNTER_OP, DPL_BLANK, - // Left aux + /* Left aux */ DPLA_DROPDOWN = 0, - // Middle + /* Middle */ DPM_COMPARATOR = 0, DPM_SLOT_OP, DPM_BLANK, - // Right + /* Right */ DPR_VALUE_INT = 0, DPR_VALUE_DECIMAL, DPR_VALUE_DROPDOWN, @@ -130,12 +130,12 @@ enum PanelWidgets { DPR_VALUE_TILE, DPR_BLANK, - // Share + /* Share */ DPS_SHARE = 0, DPS_UNSHARE, DPS_SHARE_ONTO, - // Copy + /* Copy */ DPC_COPY = 0, DPC_APPEND, DPC_DUPLICATE, @@ -660,8 +660,7 @@ static DropDownList GetGroupDropDownList(Owner owner, GroupID group_id, int &sel if (group_id == DEFAULT_GROUP) selected = DEFAULT_GROUP; dlist.push_back(MakeDropDownListStringItem(STR_GROUP_DEFAULT_TRAINS, DEFAULT_GROUP, false)); - for (size_t i = 0; i < list.size(); ++i) { - const Group *g = list[i]; + for (const Group *g : list) { if (group_id == g->index) selected = group_id; SetDParam(0, g->index | GROUP_NAME_HIERARCHY); dlist.push_back(MakeDropDownListStringItem(STR_GROUP_NAME, g->index, false)); @@ -757,8 +756,7 @@ DropDownList GetCounterDropDownList(Owner owner, TraceRestrictCounterID ctr_id, selected = -1; - for (size_t i = 0; i < list.size(); ++i) { - const TraceRestrictCounter *s = list[i]; + for (const TraceRestrictCounter *s : list) { if (ctr_id == s->index) selected = ctr_id; SetDParam(0, s->index); dlist.push_back(MakeDropDownListStringItem(STR_TRACE_RESTRICT_COUNTER_NAME, s->index, false)); @@ -1231,7 +1229,7 @@ static void DrawInstructionString(const TraceRestrictProgram *prog, TraceRestric instruction_string = STR_TRACE_RESTRICT_CONDITIONAL_ORDER_STATION; DrawInstructionStringConditionalIntegerCommon(item, properties); } else { - // this is an invalid station, use a seperate string + /* This is an invalid station, use a separate string */ DrawInstructionStringConditionalInvalidValue(item, properties, instruction_string, selected); } break; @@ -1539,7 +1537,7 @@ static void DrawInstructionString(const TraceRestrictProgram *prog, TraceRestric break; case TRIT_RESERVE_THROUGH: - instruction_string = GetTraceRestrictValue(item) ? STR_TRACE_RESTRICT_RESERVE_THROUGH_CANCEL : STR_TRACE_RESTRICT_RESERVE_THROUGH; + instruction_string = GetTraceRestrictValue(item) != 0 ? STR_TRACE_RESTRICT_RESERVE_THROUGH_CANCEL : STR_TRACE_RESTRICT_RESERVE_THROUGH; break; case TRIT_LONG_RESERVE: @@ -1813,7 +1811,7 @@ public: int sel = this->GetItemIndexFromPt(pt.y); if (_ctrl_pressed) { - // scroll to target (for stations, waypoints, depots) + /* Scroll to target (for stations, waypoints, depots) */ if (sel == -1) return; @@ -1823,16 +1821,16 @@ public: switch (static_cast(GetTraceRestrictAuxField(item))) { case TROCAF_STATION: case TROCAF_WAYPOINT: { - BaseStation *st = BaseStation::GetIfValid(GetTraceRestrictValue(item)); - if (st) { + const BaseStation *st = BaseStation::GetIfValid(GetTraceRestrictValue(item)); + if (st != nullptr) { ScrollMainWindowToTile(st->xy); } break; } case TROCAF_DEPOT: { - Depot *depot = Depot::GetIfValid(GetTraceRestrictValue(item)); - if (depot) { + const Depot *depot = Depot::GetIfValid(GetTraceRestrictValue(item)); + if (depot != nullptr) { ScrollMainWindowToTile(depot->xy); } break; @@ -1851,7 +1849,7 @@ public: HideDropDownMenu(this); if (sel == -1 || this->GetOwner() != _local_company) { - // Deselect + /* Deselect */ this->selected_instruction = -1; } else { this->selected_instruction = sel; @@ -1873,20 +1871,20 @@ public: TraceRestrictItem item = this->GetSelected(); if (GetTraceRestrictType(item) == TRIT_COND_ENDIF || (IsTraceRestrictConditional(item) && GetTraceRestrictCondFlags(item) != 0)) { - // this is either: an else/or if, an else, or an end if - // try to include else if, else in insertion list + /* This is either: an else/or if, an else, or an end if + * try to include else if, else in insertion list */ if (!ElseInsertionDryRun(false)) disabled |= _program_insert_else_hide_mask; if (!ElseIfInsertionDryRun(false)) disabled |= _program_insert_else_if_hide_mask; } else { - // can't insert else/end if here + /* Can't insert else/end if here */ disabled |= _program_insert_else_hide_mask | _program_insert_else_if_hide_mask; } if (this->selected_instruction > 1) { TraceRestrictItem prev_item = this->GetItem(this->GetProgram(), this->selected_instruction - 1); if (IsTraceRestrictConditional(prev_item) && GetTraceRestrictType(prev_item) != TRIT_COND_ENDIF) { - // previous item is either: an if, or an else/or if + /* Previous item is either: an if, or an else/or if */ - // else if has same validation rules as or if, use it instead of creating another test function + /* Else if has same validation rules as or if, use it instead of creating another test function */ if (ElseIfInsertionDryRun(false)) disabled &= ~_program_insert_or_if_hide_mask; } } @@ -1993,7 +1991,7 @@ public: case TR_WIDGET_COMPARATOR: { TraceRestrictItem item = this->GetSelected(); const TraceRestrictDropDownListSet *list_set = GetCondOpDropDownListSet(GetTraceRestrictTypeProperties(item)); - if (list_set) { + if (list_set != nullptr) { this->ShowDropDownListWithValue(list_set, GetTraceRestrictCondOp(item), false, TR_WIDGET_COMPARATOR, 0, 0); } break; @@ -2289,7 +2287,7 @@ public: if (widget == TR_WIDGET_VALUE_DROPDOWN || widget == TR_WIDGET_LEFT_AUX_DROPDOWN) { TraceRestrictTypePropertySet type = GetTraceRestrictTypeProperties(item); if (this->value_drop_down_is_company || type.value_type == TRVT_GROUP_INDEX || type.value_type == TRVT_SLOT_INDEX || type.value_type == TRVT_SLOT_INDEX_INT || type.value_type == TRVT_COUNTER_INDEX_INT || type.value_type == TRVT_TIME_DATE_INT) { - // this is a special company drop-down or group/slot-index drop-down + /* This is a special company drop-down or group/slot-index drop-down */ SetTraceRestrictValue(item, index); TraceRestrictDoCommandP(this->tile, this->track, TRDCT_MODIFY_ITEM, this->selected_instruction - 1, item, STR_TRACE_RESTRICT_ERROR_CAN_T_MODIFY_ITEM); return; @@ -2335,7 +2333,7 @@ public: SetTraceRestrictCondFlags(item, TRCF_ELSE); } else { if (GetTraceRestrictType(item) == TRIT_COND_ENDIF) { - // item is currently an else, convert to else/or if + /* Item is currently an else, convert to else/or if */ SetTraceRestrictTypeAndNormalise(item, TRIT_COND_UNDEFINED); } @@ -2449,7 +2447,7 @@ public: trackbits = (_tile_fract_coords.x + _tile_fract_coords.y <= 15) ? TRACK_BIT_UPPER : TRACK_BIT_LOWER; } Track source_track = FindFirstTrack(trackbits); - if(source_track == INVALID_TRACK) { + if (source_track == INVALID_TRACK) { ShowErrorMessage(error_message, STR_ERROR_THERE_IS_NO_RAILROAD_TRACK, WL_INFO); return; } @@ -2557,9 +2555,9 @@ public: } if (IsRailDepotTile(tile)) { - // OK + /* OK */ } else if (IsTileType(tile, MP_TUNNELBRIDGE) && IsTunnelBridgeWithSignalSimulation(tile)) { - // OK + /* OK */ } else { if (!IsPlainRailTile(tile)) { ShowErrorMessage(error_message, STR_ERROR_THERE_IS_NO_RAILROAD_TRACK, WL_INFO); @@ -2626,7 +2624,7 @@ public: int line_height = this->GetWidget(TR_WIDGET_INSTRUCTION_LIST)->resize_y; int scroll_position = this->vscroll->GetPosition(); - // prog may be nullptr + /* prog may be nullptr */ const TraceRestrictProgram *prog = this->GetProgram(); int count = this->GetItemCount(prog); @@ -2696,7 +2694,7 @@ public: case TR_WIDGET_CAPTION: { const TraceRestrictProgram *prog = this->GetProgram(); - if (prog) { + if (prog != nullptr) { SetDParam(0, prog->refcount); } else { SetDParam(0, 1); @@ -2786,8 +2784,8 @@ private: */ int GetItemCount(const TraceRestrictProgram *prog) const { - if (prog) { - return 2 + (int)prog->GetInstructionCount(); + if (prog != nullptr) { + return 2 + static_cast(prog->GetInstructionCount()); } else { return 2; } @@ -2818,7 +2816,7 @@ private: return MakeSpecialItem(TRNTSV_START); } - if (prog) { + if (prog != nullptr) { size_t instruction_count = prog->GetInstructionCount(); if (static_cast(index) == instruction_count + 1) { @@ -2831,7 +2829,7 @@ private: return prog->items[prog->InstructionOffsetToArrayOffset(index - 1)]; } else { - // No program defined, this is equivalent to an empty program + /* No program defined, this is equivalent to an empty program */ if (index == 1) { return MakeSpecialItem(TRNTSV_END); } else { @@ -2879,16 +2877,16 @@ private: const TraceRestrictProgram *prog = this->GetProgram(); if (this->vscroll->GetCount() != this->GetItemCount(prog)) { - // program length has changed + /* Program length has changed */ if (this->GetItemCount(prog) < this->vscroll->GetCount() || this->GetItem(prog, this->selected_instruction) != this->expecting_inserted_item) { - // length has shrunk or if we weren't expecting an insertion, deselect + /* Length has shrunk or if we weren't expecting an insertion, deselect */ this->selected_instruction = -1; } this->expecting_inserted_item = static_cast(0); - // update scrollbar size + /* Update scrollbar size */ this->vscroll->SetCount(this->GetItemCount(prog)); } this->UpdateButtonState(); @@ -2896,7 +2894,7 @@ private: bool IsUpDownBtnUsable(bool up, bool update_selection = false) { const TraceRestrictProgram *prog = this->GetProgram(); - if (!prog) return false; + if (prog == nullptr) return false; TraceRestrictItem item = this->GetSelected(); if (GetTraceRestrictType(item) == TRIT_NULL) return false; @@ -2916,7 +2914,7 @@ private: bool IsDuplicateBtnUsable() const { const TraceRestrictProgram *prog = this->GetProgram(); - if (!prog) return false; + if (prog == nullptr) return false; TraceRestrictItem item = this->GetSelected(); if (GetTraceRestrictType(item) == TRIT_NULL) return false; @@ -3013,7 +3011,7 @@ private: const TraceRestrictProgram *prog = this->GetProgram(); this->GetWidget(TR_WIDGET_CAPTION)->widget_data = - (prog && prog->refcount > 1) ? STR_TRACE_RESTRICT_CAPTION_SHARED : STR_TRACE_RESTRICT_CAPTION; + (prog != nullptr && prog->refcount > 1) ? STR_TRACE_RESTRICT_CAPTION_SHARED : STR_TRACE_RESTRICT_CAPTION; this->SetWidgetDisabledState(TR_WIDGET_HIGHLIGHT, prog == nullptr); extern const TraceRestrictProgram *_viewport_highlight_tracerestrict_program; @@ -3026,7 +3024,7 @@ private: } }); - // Don't allow modifications if don't own + /* Don't allow modifications for non-owners */ if (this->GetOwner() != _local_company) { this->SetDirty(); return; @@ -3039,15 +3037,15 @@ private: this->base_share_plane = DPS_SHARE; if (prog != nullptr && prog->refcount > 1) { - // program is shared, show and enable unshare button, and reset button + /* Program is shared, show and enable unshare button, and reset button */ this->base_share_plane = DPS_UNSHARE; this->EnableWidget(TR_WIDGET_UNSHARE); this->EnableWidget(TR_WIDGET_RESET); } else if (this->GetItemCount(prog) > 2) { - // program is non-empty and not shared, enable reset button + /* Program is non-empty and not shared, enable reset button */ this->EnableWidget(TR_WIDGET_RESET); } else { - // program is empty and not shared, show copy and share buttons + /* Program is empty and not shared, show copy and share buttons */ this->EnableWidget(TR_WIDGET_COPY); this->EnableWidget(TR_WIDGET_SHARE); this->base_copy_plane = DPC_COPY; @@ -3056,7 +3054,7 @@ private: this->GetWidget(TR_WIDGET_COPY_APPEND)->tool_tip = (this->base_copy_plane == DPC_DUPLICATE) ? STR_TRACE_RESTRICT_DUPLICATE_TOOLTIP : STR_TRACE_RESTRICT_COPY_TOOLTIP; this->UpdatePlaceObjectPlanes(); - // haven't selected instruction + /* Haven't selected instruction */ if (this->selected_instruction < 1) { this->SetDirty(); return; @@ -3080,10 +3078,10 @@ private: } else if (GetTraceRestrictType(item) == TRIT_COND_ENDIF) { this->EnableWidget(TR_WIDGET_INSERT); if (GetTraceRestrictCondFlags(item) != 0) { - // this is not an end if, it must be an else, enable removing + /* This is not an end if, it must be an else, enable removing */ this->EnableWidget(TR_WIDGET_REMOVE); - // setup condflags dropdown to show else + /* Setup condflags dropdown to show else */ left_2_sel->SetDisplayedPlane(DPL2_CONDFLAGS); this->EnableWidget(TR_WIDGET_CONDFLAGS); this->GetWidget(TR_WIDGET_CONDFLAGS)->widget_data = STR_TRACE_RESTRICT_CONDITIONAL_ELSE; @@ -3093,13 +3091,13 @@ private: int type_widget; if (IsTraceRestrictConditional(item)) { - // note that else and end if items are not handled here, they are handled above + /* Note that else and end if items are not handled here, they are handled above */ left_2_sel->SetDisplayedPlane(DPL2_CONDFLAGS); left_sel->SetDisplayedPlane(DPL_TYPE); type_widget = TR_WIDGET_TYPE_COND; - // setup condflags dropdown box + /* Setup condflags dropdown box */ left_2_sel->SetDisplayedPlane(DPL2_CONDFLAGS); switch (GetTraceRestrictCondFlags(item)) { case TRCF_DEFAULT: // opening if, leave disabled @@ -3144,7 +3142,7 @@ private: if (IsIntegerValueType(properties.value_type)) { right_sel->SetDisplayedPlane(DPR_VALUE_INT); this->EnableWidget(TR_WIDGET_VALUE_INT); - } else if(IsDecimalValueType(properties.value_type)) { + } else if (IsDecimalValueType(properties.value_type)) { right_sel->SetDisplayedPlane(DPR_VALUE_DECIMAL); this->EnableWidget(TR_WIDGET_VALUE_DECIMAL); } else { @@ -3436,7 +3434,7 @@ private: { DropDownList list; - for (Company *c : Company::Iterate()) { + for (const Company *c : Company::Iterate()) { list.emplace_back(MakeCompanyDropDownListItem(c->index)); if (c->index == value) missing_ok = true; } @@ -3487,13 +3485,13 @@ private: uint offset = this->selected_instruction - 1; const TraceRestrictProgram *prog = this->GetProgram(); - if (!prog) return false; + if (prog == nullptr) return false; std::vector items = prog->items; // copy if (offset >= (TraceRestrictProgram::GetInstructionCount(items) + (replace ? 0 : 1))) return false; // off the end of the program - uint array_offset = (uint)TraceRestrictProgram::InstructionOffsetToArrayOffset(items, offset); + uint array_offset = static_cast(TraceRestrictProgram::InstructionOffsetToArrayOffset(items, offset)); if (replace) { items[array_offset] = item; } else { @@ -3528,7 +3526,7 @@ private: }; static constexpr NWidgetPart _nested_program_widgets[] = { - // Title bar + /* Title bar */ NWidget(NWID_HORIZONTAL), NWidget(WWT_CLOSEBOX, COLOUR_GREY), NWidget(WWT_CAPTION, COLOUR_GREY, TR_WIDGET_CAPTION), SetDataTip(STR_TRACE_RESTRICT_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS), @@ -3538,14 +3536,14 @@ static constexpr NWidgetPart _nested_program_widgets[] = { NWidget(WWT_STICKYBOX, COLOUR_GREY), EndContainer(), - // Program display + /* Program display */ NWidget(NWID_HORIZONTAL), NWidget(WWT_PANEL, COLOUR_GREY, TR_WIDGET_INSTRUCTION_LIST), SetMinimalSize(372, 62), SetDataTip(0x0, STR_TRACE_RESTRICT_INSTRUCTION_LIST_TOOLTIP), SetResize(1, 1), SetScrollbar(TR_WIDGET_SCROLLBAR), EndContainer(), NWidget(NWID_VSCROLLBAR, COLOUR_GREY, TR_WIDGET_SCROLLBAR), EndContainer(), - // Button Bar + /* Button Bar */ NWidget(NWID_HORIZONTAL), NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, TR_WIDGET_UP_BTN), SetMinimalSize(12, 12), SetDataTip(SPR_ARROW_UP, STR_TRACE_RESTRICT_UP_BTN_TOOLTIP), NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, TR_WIDGET_DOWN_BTN), SetMinimalSize(12, 12), SetDataTip(SPR_ARROW_DOWN, STR_TRACE_RESTRICT_DOWN_BTN_TOOLTIP), @@ -3734,8 +3732,8 @@ private: TraceRestrictSlotID slot_rename; ///< Slot being renamed or max occupancy changed, INVALID_TRACE_RESTRICT_SLOT_ID if none TraceRestrictSlotID slot_over; ///< Slot over which a vehicle is dragged, INVALID_TRACE_RESTRICT_SLOT_ID if none TraceRestrictSlotID slot_confirm; ///< Slot awaiting delete confirmation - GUIList slots; ///< List of slots - uint tiny_step_height; ///< Step height for the slot list + GUIList slots; ///< List of slots + uint tiny_step_height; ///< Step height for the slot list Scrollbar *slot_sb; Dimension column_size[VGC_END]; ///< Size of the columns in the group list. @@ -3781,8 +3779,8 @@ private: this->tiny_step_height += WidgetDimensions::scaled.matrix.top + ScaleGUITrad(1); return WidgetDimensions::scaled.framerect.Horizontal() + WidgetDimensions::scaled.vsep_wide + - this->column_size[VGC_NAME].width + WidgetDimensions::scaled.vsep_wide + - this->column_size[VGC_NUMBER].width + WidgetDimensions::scaled.vsep_normal; + this->column_size[VGC_NAME].width + WidgetDimensions::scaled.vsep_wide + + this->column_size[VGC_NUMBER].width + WidgetDimensions::scaled.vsep_normal; } /** @@ -3812,7 +3810,13 @@ private: SetDParam(0, slot_id); str = STR_TRACE_RESTRICT_SLOT_NAME; } - int x = rtl ? right - WidgetDimensions::scaled.framerect.right - WidgetDimensions::scaled.vsep_wide - this->column_size[VGC_NAME].width + 1 : left + WidgetDimensions::scaled.framerect.left + WidgetDimensions::scaled.vsep_wide; + + int x; + if (rtl) { + x = right - WidgetDimensions::scaled.framerect.right - WidgetDimensions::scaled.vsep_wide - this->column_size[VGC_NAME].width + 1; + } else { + x = left + WidgetDimensions::scaled.framerect.left + WidgetDimensions::scaled.vsep_wide; + } DrawString(x, x + this->column_size[VGC_NAME].width - 1, y + (this->tiny_step_height - this->column_size[VGC_NAME].height) / 2, str, colour); if (slot_id == ALL_TRAINS_TRACE_RESTRICT_SLOT_ID) return; @@ -3976,8 +3980,8 @@ public: this->BuildSlotList(this->owner); - this->slot_sb->SetCount((uint)this->slots.size()); - this->vscroll->SetCount((uint)this->vehgroups.size()); + this->slot_sb->SetCount(static_cast(this->slots.size())); + this->vscroll->SetCount(static_cast(this->vehgroups.size())); /* Disable the slot specific function when we select all vehicles */ this->SetWidgetsDisabledState(this->vli.index == ALL_TRAINS_TRACE_RESTRICT_SLOT_ID || _local_company != this->vli.company, @@ -4011,7 +4015,7 @@ public: case WID_TRSL_LIST_SLOTS: { int y1 = r.top + WidgetDimensions::scaled.framerect.top; - int max = std::min(this->slot_sb->GetPosition() + this->slot_sb->GetCapacity(), (int)this->slots.size()); + int max = std::min(this->slot_sb->GetPosition() + this->slot_sb->GetCapacity(), static_cast(this->slots.size())); for (int i = this->slot_sb->GetPosition(); i < max; ++i) { const TraceRestrictSlot *slot = this->slots[i]; @@ -4142,7 +4146,7 @@ public: if (id_s >= this->slots.size()) return; // click out of list bound if (_ctrl_pressed) { - // remove from old group + /* Remove from old group */ DoCommandP(0, this->slot_sel, vindex, CMD_REMOVE_VEHICLE_TRACERESTRICT_SLOT | CMD_MSG(STR_TRACE_RESTRICT_ERROR_SLOT_CAN_T_REMOVE_VEHICLE)); } DoCommandP(0, this->slots[id_s]->index, vindex, CMD_ADD_VEHICLE_TRACERESTRICT_SLOT | CMD_MSG(STR_TRACE_RESTRICT_ERROR_SLOT_CAN_T_ADD_VEHICLE)); @@ -4221,7 +4225,7 @@ public: virtual void OnPlaceObjectAbort() override { - /* abort drag & drop */ + /* Abort drag & drop */ this->vehicle_sel = INVALID_VEHICLE; this->DirtyHighlightedSlotWidget(); this->slot_over = INVALID_GROUP; @@ -4389,9 +4393,9 @@ private: TraceRestrictCounterID ctr_qt_op; ///< Counter being adjusted in query text operation, INVALID_TRACE_RESTRICT_COUNTER_ID if none TraceRestrictCounterID ctr_confirm; ///< Counter awaiting delete confirmation TraceRestrictCounterID selected; ///< Selected counter - GUIList ctrs; ///< List of slots - uint tiny_step_height; ///< Step height for the counter list - uint value_col_width; ///< Value column width + GUIList ctrs; ///< List of slots + uint tiny_step_height; ///< Step height for the counter list + uint value_col_width; ///< Value column width Scrollbar *sb; void BuildCounterList() @@ -4424,9 +4428,9 @@ private: this->value_col_width = dim.width; return WidgetDimensions::scaled.framerect.Horizontal() + WidgetDimensions::scaled.vsep_wide + - 170 + WidgetDimensions::scaled.vsep_wide + - dim.width + WidgetDimensions::scaled.vsep_wide + - WidgetDimensions::scaled.framerect.right; + 170 + WidgetDimensions::scaled.vsep_wide + + dim.width + WidgetDimensions::scaled.vsep_wide + + WidgetDimensions::scaled.framerect.right; } /** @@ -4516,7 +4520,7 @@ public: { this->BuildCounterList(); - this->sb->SetCount((uint)this->ctrs.size()); + this->sb->SetCount(static_cast(this->ctrs.size())); /* Disable the counter specific functions when no counter is selected */ this->SetWidgetsDisabledState(this->selected == INVALID_TRACE_RESTRICT_COUNTER_ID || _local_company != this->ctr_company, @@ -4542,7 +4546,7 @@ public: case WID_TRCL_LIST_COUNTERS: { Rect ir = r.Shrink(WidgetDimensions::scaled.framerect); int y1 = ir.top; - int max = std::min(this->sb->GetPosition() + this->sb->GetCapacity(), (int)this->ctrs.size()); + int max = std::min(this->sb->GetPosition() + this->sb->GetCapacity(), static_cast(this->ctrs.size())); for (int i = this->sb->GetPosition(); i < max; ++i) { const TraceRestrictCounter *ctr = this->ctrs[i];