Skip to content

Commit

Permalink
ADD: new vehicle parameter - mixed_load_prohibition
Browse files Browse the repository at this point in the history
The setting of mixed loading prohibition on the vehicle becomes possible
  • Loading branch information
Ranran-the-JuicyPork committed Jul 10, 2019
1 parent 554a641 commit 4d323ad
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 9 deletions.
10 changes: 10 additions & 0 deletions descriptor/reader/vehicle_reader.cc
Expand Up @@ -513,6 +513,7 @@ obj_desc_t *vehicle_reader_t::read_node(FILE *fp, obj_node_info_t &node)
desc->can_be_at_rear = (bool)decode_uint8(p);
desc->basic_constraint_prev = vehicle_desc_t::unknown_constraint;
desc->basic_constraint_next = vehicle_desc_t::unknown_constraint;
desc->mixed_load_prohibition = false;
}
desc->increase_maintenance_after_years = decode_uint16(p);
desc->increase_maintenance_by_percent = decode_uint16(p);
Expand Down Expand Up @@ -542,6 +543,14 @@ obj_desc_t *vehicle_reader_t::read_node(FILE *fp, obj_node_info_t &node)
{
desc->is_tall = false;
}
if (extended && extended_version >= 5)
{
desc->mixed_load_prohibition = decode_uint8(p);
}
else
{
desc->mixed_load_prohibition = false;
}
}
else
{
Expand Down Expand Up @@ -668,6 +677,7 @@ obj_desc_t *vehicle_reader_t::read_node(FILE *fp, obj_node_info_t &node)
desc->is_tall = false;
desc->basic_constraint_prev = vehicle_desc_t::unknown_constraint;
desc->basic_constraint_next = vehicle_desc_t::unknown_constraint;
desc->mixed_load_prohibition = false;
}
desc->set_way_constraints(way_constraints);

Expand Down
4 changes: 4 additions & 0 deletions descriptor/vehicle_desc.h
Expand Up @@ -226,6 +226,9 @@ class vehicle_desc_t : public obj_desc_transport_related_t {
//@jamespetts January 2017
bool is_tall;

// if true, can not mix another goods in the same car. @Ranran, July 2019(v14.6)
bool mixed_load_prohibition;

// @author: Bernd Gabriel, Dec 12, 2009: called as last action in read_node()
void loaded();

Expand Down Expand Up @@ -807,6 +810,7 @@ class vehicle_desc_t : public obj_desc_transport_related_t {
uint32 get_way_wear_factor() const { return way_wear_factor; }

bool get_is_tall() const { return is_tall; }
bool get_mixed_load_prohibition() const { return mixed_load_prohibition; }

void set_scale(uint16 scale_factor, uint32 way_wear_factor_rail, uint32 way_wear_factor_road, uint16 standard_axle_load)
{
Expand Down
6 changes: 5 additions & 1 deletion descriptor/writer/vehicle_writer.cc
Expand Up @@ -82,7 +82,7 @@ void vehicle_writer_t::write_obj(FILE* fp, obj_node_t& parent, tabfileobj_t& obj
int i;
uint8 uv8;

int total_len = 86;
int total_len = 87;

// prissi: must be done here, since it may affect the len of the header!
string sound_str = ltrim( obj.get("sound") );
Expand Down Expand Up @@ -1092,6 +1092,10 @@ void vehicle_writer_t::write_obj(FILE* fp, obj_node_t& parent, tabfileobj_t& obj
node.write_uint8(fp, is_tall, pos);
pos += sizeof(is_tall);

uint8 mixed_load_prohibition = obj.get_int("mixed_load_prohibition", 0);
node.write_uint8(fp, mixed_load_prohibition, pos);
pos += sizeof(mixed_load_prohibition);

sint8 sound_str_len = sound_str.size();
if (sound_str_len > 0) {
node.write_sint8 (fp, sound_str_len, pos);
Expand Down
5 changes: 5 additions & 0 deletions gui/components/gui_convoy_assembler.cc
Expand Up @@ -2360,6 +2360,11 @@ void gui_convoy_assembler_t::draw_vehicle_info_text(const scr_coord& pos)
"\0",
translator::translate(veh_type->get_freight_type()->get_mass()),
translator::translate(veh_type->get_freight_type()->get_catg_name()));
if (veh_type->get_mixed_load_prohibition())
{
buf.printf(" %s", translator::translate("(mixed_load_prohibition)"));
}
buf.append("\n");
display_proportional(pos.x + 335 + left, top, buf, ALIGN_LEFT, SYSCOL_TEXT, true);
buf.clear();
top += LINESPACE;
Expand Down
7 changes: 6 additions & 1 deletion gui/convoi_detail_t.cc
Expand Up @@ -775,7 +775,6 @@ void gui_convoy_cargo_info_t::draw(scr_coord offset)
goods_desc_t const* const wtyp = ware.get_desc();
cargo_sum += ware.menge;

buf.clear();
// draw the goods loading bar
int bar_end_offset = cargo_sum * LOADING_BAR_WIDTH / v->get_desc()->get_total_capacity();
COLOR_VAL goods_color = wtyp->get_color();
Expand All @@ -787,6 +786,12 @@ void gui_convoy_cargo_info_t::draw(scr_coord offset)
}
bar_start_offset += bar_end_offset - bar_start_offset;
}
if (v->get_desc()->get_mixed_load_prohibition()) {
extra_y += LINESPACE;
buf.clear();
buf.printf("%s", translator::translate("(mixed_load_prohibition)"));
display_proportional_clip(pos.x + extra_w + offset.x, pos.y + offset.y + total_height + extra_y - (LINESPACE - LOADING_BAR_HEIGHT) / 2, buf, ALIGN_LEFT, SYSCOL_TEXT, true);
}
extra_y += LINESPACE + 2;
}

Expand Down
16 changes: 14 additions & 2 deletions simhalt.cc
Expand Up @@ -2345,7 +2345,7 @@ bool haltestelle_t::recall_ware( ware_t& w, uint32 menge )
}


bool haltestelle_t::fetch_goods(slist_tpl<ware_t> &load, const goods_desc_t *good_category, sint32 requested_amount, const schedule_t *schedule, const player_t *player, convoi_t* cnv, bool overcrowded, const uint8 g_class, const bool use_lower_classes, bool& other_classes_available)
bool haltestelle_t::fetch_goods(slist_tpl<ware_t> &load, const goods_desc_t *good_category, sint32 requested_amount, const schedule_t *schedule, const player_t *player, convoi_t* cnv, bool overcrowded, const uint8 g_class, const bool use_lower_classes, bool& other_classes_available, const bool mixed_load_prohibition, uint8 goods_restriction)
{
bool skipped = false;
const uint8 catg_index = good_category->get_catg_index();
Expand All @@ -2361,7 +2361,19 @@ bool haltestelle_t::fetch_goods(slist_tpl<ware_t> &load, const goods_desc_t *goo
if(ware->menge > 0)
{
i++;
if (ware->get_class() >= g_class)
if (mixed_load_prohibition) {
// this vehicle only load with the same kind of goods initially loaded
if (!goods_restriction) {
goods_restriction = ware->get_index();
}
if (ware->get_index() == goods_restriction) {
goods_to_check.insert(ware);
}
else {
other_classes_available = true;
}
}
else if (ware->get_class() >= g_class)
{
// We know at this stage that we cannot load passengers of a *lower* class into higher class accommodation,
// but we cannot yet know whether or not to load passengers of a higher class into lower class accommodation.
Expand Down
2 changes: 1 addition & 1 deletion simhalt.h
Expand Up @@ -741,7 +741,7 @@ class haltestelle_t
* @param player Company that's requesting the fetch.
* @author Dwachs
*/
bool fetch_goods( slist_tpl<ware_t> &load, const goods_desc_t *good_category, sint32 requested_amount, const schedule_t *schedule, const player_t *player, convoi_t* cnv, bool overcrowd, const uint8 g_class, const bool use_lower_classes, bool& other_classes_available);
bool fetch_goods( slist_tpl<ware_t> &load, const goods_desc_t *good_category, sint32 requested_amount, const schedule_t *schedule, const player_t *player, convoi_t* cnv, bool overcrowd, const uint8 g_class, const bool use_lower_classes, bool& other_classes_available, const bool mixed_load_prohibition, uint8 goods_restriction);

/* liefert ware an. Falls die Ware zu wartender Ware dazugenommen
* werden kann, kann ware_t gelöscht werden! D.h. man darf ware nach
Expand Down
4 changes: 2 additions & 2 deletions simversion.h
Expand Up @@ -33,8 +33,8 @@ extern "C" FILE * __cdecl __iob_func(void) { return _iob; }

// Do not forget to increment the save game versions in settings_stats.cc when changing this

#define MAKEOBJ_VERSION "60.05"
// Transparency and new factories(60.0), railcar_tab(60.01), basic constraint extension(60.05). NOTE: standard now 60.2
#define MAKEOBJ_VERSION "60.06"
// Transparency and new factories(60.0), railcar_tab(60.01), basic constraint + mixed_load_prohibition(60.06). NOTE: standard now 60.2

#ifndef QUOTEME
# define QUOTEME_(x) #x
Expand Down
11 changes: 9 additions & 2 deletions vehicle/simvehicle.cc
Expand Up @@ -1075,6 +1075,7 @@ bool vehicle_t::load_freight_internal(halthandle_t halt, bool overcrowd, bool *s
{
const uint16 total_capacity = desc->get_total_capacity() + (overcrowd ? desc->get_overcrowded_capacity() : 0);
bool other_classes_available = false;
uint8 goods_restriction = 0;
if (total_freight < total_capacity)
{
schedule_t *schedule = cnv->get_schedule();
Expand All @@ -1085,7 +1086,13 @@ bool vehicle_t::load_freight_internal(halthandle_t halt, bool overcrowd, bool *s
uint8 lowest_class_with_nonzero_capacity = 255;

*skip_vehicles = true;

if (!fracht[0].empty() && desc->get_mixed_load_prohibition()) {
FOR(slist_tpl<ware_t>, const& w, fracht[0])
{
goods_restriction = w.index;
break;
}
}
for (uint8 i = 0; i < number_of_classes; i++)
{
capacity_this_class = get_accommodation_capacity(i);
Expand Down Expand Up @@ -1126,7 +1133,7 @@ bool vehicle_t::load_freight_internal(halthandle_t halt, bool overcrowd, bool *s
// the need for higher class passengers/mail to use lower class accommodation.
if (capacity_left_this_class >= 0)
{
*skip_vehicles &= halt->fetch_goods(freight_add, desc->get_freight_type(), capacity_left_this_class, schedule, cnv->get_owner(), cnv, overcrowd, class_reassignments[i], use_lower_classes, other_classes_available);
*skip_vehicles &= halt->fetch_goods(freight_add, desc->get_freight_type(), capacity_left_this_class, schedule, cnv->get_owner(), cnv, overcrowd, class_reassignments[i], use_lower_classes, other_classes_available, desc->get_mixed_load_prohibition(), goods_restriction);
if (!freight_add.empty())
{
cnv->invalidate_weight_summary();
Expand Down

0 comments on commit 4d323ad

Please sign in to comment.