Dev - No auto-servicing when breakdown desactivated

OpenTTD is a fully open-sourced reimplementation of TTD, written in C++, boasting improved gameplay and many new features.

Moderator: OpenTTD Developers

Post Reply
User avatar
MagicBuzz
Tycoon
Tycoon
Posts: 1354
Joined: 15 Feb 2003 17:32
Location: Vergezac, France

Dev - No auto-servicing when breakdown desactivated

Post by MagicBuzz »

I was trying to undertstand anything in the source code (I never writed a line of c :D) and I found the function that check is road vehicule needs servicing.

Code: Select all

static void CheckIfRoadVehNeedsService(Vehicle *v)
{
	int i;

	if (v->date_of_last_service + v->service_interval > _date)
		return;

	if (v->vehstatus & VS_STOPPED)
		return;
	
	// Don't interfere with a depot visit scheduled by the user, or a
	// depot visit by the order list.
	if ((v->next_order & OT_MASK) == OT_GOTO_DEPOT &&
			(v->next_order & (OF_FULL_LOAD|OF_UNLOAD)) != 0)
		return;

	i = FindClosestRoadDepot(v);

	if (i < 0 || GetTileDist(v->tile, (&_depots[i])->xy) > 12) {
		if ((v->next_order & OT_MASK) == OT_GOTO_DEPOT) {
			v->next_order = OT_DUMMY;
			InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, 4);
		}
		return;
	}

	if (v->next_order == (OT_GOTO_DEPOT | OF_NON_STOP) && !CHANCE16(1,20))
		return;

	v->next_order = OT_GOTO_DEPOT | OF_NON_STOP;
	v->next_order_param = (byte)i;
	v->dest_tile = (&_depots[i])->xy;
	InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, 4);		
}
Can add these two lines at the begining of the function ?

Code: Select all

	/* disabled breakdowns? */
	if (_opt.diff.vehicle_breakdowns < 1)
		return;
And then, here is the CheckVehicleBreakdown() function (vehicule.c)
=> If no breakdown, then... Reliability is always 100% right ? So... Juste move the tow lines bellow "/* disabled breakdowns? */" to the begining of the function. It would save (a very few) CPU usage :)

Code: Select all

void CheckVehicleBreakdown(Vehicle *v)
{
	int rel, rel_old;
	uint32 r;
	int chance;

	/* decrease reliability */
	v->reliability = rel = max((rel_old = v->reliability) - v->reliability_spd_dec, 0);
	if ((rel_old >> 8) != (rel >> 8))
		InvalidateWindow(WC_VEHICLE_DETAILS, v->index);

	if (v->breakdown_ctr != 0 || (v->vehstatus & VS_STOPPED) != 0 ||
			v->cur_speed < 5 || _game_mode == GM_MENU)
				return;

	r = Random();

	/* increase chance of failure */
	chance = v->breakdown_chance + 1;
	if (CHANCE16I(1,25,r)) chance += 25;
	v->breakdown_chance = min(255, chance);

	/* calculate reliability value to use in comparison */
	rel = v->reliability;
	if (v->type == VEH_Ship) rel += 0x6666;
	
	/* disabled breakdowns? */
	if (_opt.diff.vehicle_breakdowns < 1)
		return;

	/* reduced breakdowns? */
	if (_opt.diff.vehicle_breakdowns == 1) rel += 0x6666;

	/* check if to break down */
	if (_breakdown_chance[(uint)min(rel, 0xffff) >> 10] <= v->breakdown_chance) {
		v->breakdown_ctr = (byte)(((r >> 16) & 0x3F) + 0x3F);
		v->breakdown_delay = (byte)(((r >> 24) & 0x7F) | 0x80);
		v->breakdown_chance = 0;
	}
}
I didn't find the code for vehicule window to look if possible to remove the "servincing interval" line.

Should be same code for ships and airplanes.
Post Reply

Return to “General OpenTTD”

Who is online

Users browsing this forum: No registered users and 8 guests