mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r22858) -Feature: Conditional order depending on remaining lifetime of a vehicle. (monoid)
This commit is contained in:
parent
c9982cfbd4
commit
4e5d841d66
|
@ -3198,12 +3198,15 @@ STR_ORDER_DROP_HALT_DEPOT :Stop
|
||||||
STR_ORDER_SERVICE_TOOLTIP :{BLACK}Skip this order unless a service is needed
|
STR_ORDER_SERVICE_TOOLTIP :{BLACK}Skip this order unless a service is needed
|
||||||
|
|
||||||
STR_ORDER_CONDITIONAL_VARIABLE_TOOLTIP :{BLACK}Vehicle data to base jumping on
|
STR_ORDER_CONDITIONAL_VARIABLE_TOOLTIP :{BLACK}Vehicle data to base jumping on
|
||||||
|
|
||||||
|
# Conditional order variables, must follow order of OrderConditionVariable enum
|
||||||
STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE :Load percentage
|
STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE :Load percentage
|
||||||
STR_ORDER_CONDITIONAL_RELIABILITY :Reliability
|
STR_ORDER_CONDITIONAL_RELIABILITY :Reliability
|
||||||
STR_ORDER_CONDITIONAL_MAX_SPEED :Maximum speed
|
STR_ORDER_CONDITIONAL_MAX_SPEED :Maximum speed
|
||||||
STR_ORDER_CONDITIONAL_AGE :Vehicle age (years)
|
STR_ORDER_CONDITIONAL_AGE :Age (years)
|
||||||
STR_ORDER_CONDITIONAL_REQUIRES_SERVICE :Requires service
|
STR_ORDER_CONDITIONAL_REQUIRES_SERVICE :Requires service
|
||||||
STR_ORDER_CONDITIONAL_UNCONDITIONALLY :Always
|
STR_ORDER_CONDITIONAL_UNCONDITIONALLY :Always
|
||||||
|
STR_ORDER_CONDITIONAL_REMAINING_LIFETIME :Remaining lifetime (years)
|
||||||
|
|
||||||
STR_ORDER_CONDITIONAL_COMPARATOR_TOOLTIP :{BLACK}How to compare the vehicle data to the given value
|
STR_ORDER_CONDITIONAL_COMPARATOR_TOOLTIP :{BLACK}How to compare the vehicle data to the given value
|
||||||
STR_ORDER_CONDITIONAL_COMPARATOR_EQUALS :is equal to
|
STR_ORDER_CONDITIONAL_COMPARATOR_EQUALS :is equal to
|
||||||
|
|
|
@ -1799,12 +1799,13 @@ VehicleOrderID ProcessConditionalOrder(const Order *order, const Vehicle *v)
|
||||||
uint16 value = order->GetConditionValue();
|
uint16 value = order->GetConditionValue();
|
||||||
|
|
||||||
switch (order->GetConditionVariable()) {
|
switch (order->GetConditionVariable()) {
|
||||||
case OCV_LOAD_PERCENTAGE: skip_order = OrderConditionCompare(occ, CalcPercentVehicleFilled(v, NULL), value); break;
|
case OCV_LOAD_PERCENTAGE: skip_order = OrderConditionCompare(occ, CalcPercentVehicleFilled(v, NULL), value); break;
|
||||||
case OCV_RELIABILITY: skip_order = OrderConditionCompare(occ, ToPercent16(v->reliability), value); break;
|
case OCV_RELIABILITY: skip_order = OrderConditionCompare(occ, ToPercent16(v->reliability), value); break;
|
||||||
case OCV_MAX_SPEED: skip_order = OrderConditionCompare(occ, v->GetDisplayMaxSpeed() * 10 / 16, value); break;
|
case OCV_MAX_SPEED: skip_order = OrderConditionCompare(occ, v->GetDisplayMaxSpeed() * 10 / 16, value); break;
|
||||||
case OCV_AGE: skip_order = OrderConditionCompare(occ, v->age / DAYS_IN_LEAP_YEAR, value); break;
|
case OCV_AGE: skip_order = OrderConditionCompare(occ, v->age / DAYS_IN_LEAP_YEAR, value); break;
|
||||||
case OCV_REQUIRES_SERVICE: skip_order = OrderConditionCompare(occ, v->NeedsServicing(), value); break;
|
case OCV_REQUIRES_SERVICE: skip_order = OrderConditionCompare(occ, v->NeedsServicing(), value); break;
|
||||||
case OCV_UNCONDITIONALLY: skip_order = true; break;
|
case OCV_UNCONDITIONALLY: skip_order = true; break;
|
||||||
|
case OCV_REMAINING_LIFETIME: skip_order = OrderConditionCompare(occ, max(v->max_age - v->age + DAYS_IN_LEAP_YEAR - 1, 0) / DAYS_IN_LEAP_YEAR, value); break;
|
||||||
default: NOT_REACHED();
|
default: NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include "strings_func.h"
|
#include "strings_func.h"
|
||||||
#include "window_func.h"
|
#include "window_func.h"
|
||||||
#include "company_func.h"
|
#include "company_func.h"
|
||||||
|
#include "widgets/dropdown_type.h"
|
||||||
#include "widgets/dropdown_func.h"
|
#include "widgets/dropdown_func.h"
|
||||||
#include "textbuf_gui.h"
|
#include "textbuf_gui.h"
|
||||||
#include "string_func.h"
|
#include "string_func.h"
|
||||||
|
@ -134,14 +135,15 @@ static const StringID _order_goto_dropdown_aircraft[] = {
|
||||||
INVALID_STRING_ID
|
INVALID_STRING_ID
|
||||||
};
|
};
|
||||||
|
|
||||||
static const StringID _order_conditional_variable[] = {
|
/** Variables for conditional orders; this defines the order of appearance in the dropdown box */
|
||||||
STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE,
|
static const OrderConditionVariable _order_conditional_variable[] = {
|
||||||
STR_ORDER_CONDITIONAL_RELIABILITY,
|
OCV_LOAD_PERCENTAGE,
|
||||||
STR_ORDER_CONDITIONAL_MAX_SPEED,
|
OCV_RELIABILITY,
|
||||||
STR_ORDER_CONDITIONAL_AGE,
|
OCV_MAX_SPEED,
|
||||||
STR_ORDER_CONDITIONAL_REQUIRES_SERVICE,
|
OCV_AGE,
|
||||||
STR_ORDER_CONDITIONAL_UNCONDITIONALLY,
|
OCV_REMAINING_LIFETIME,
|
||||||
INVALID_STRING_ID,
|
OCV_REQUIRES_SERVICE,
|
||||||
|
OCV_UNCONDITIONALLY,
|
||||||
};
|
};
|
||||||
|
|
||||||
static const StringID _order_conditional_condition[] = {
|
static const StringID _order_conditional_condition[] = {
|
||||||
|
@ -783,8 +785,8 @@ public:
|
||||||
|
|
||||||
case ORDER_WIDGET_COND_VARIABLE: {
|
case ORDER_WIDGET_COND_VARIABLE: {
|
||||||
Dimension d = {0, 0};
|
Dimension d = {0, 0};
|
||||||
for (int i = 0; _order_conditional_variable[i] != INVALID_STRING_ID; i++) {
|
for (uint i = 0; i < lengthof(_order_conditional_variable); i++) {
|
||||||
d = maxdim(d, GetStringBoundingBox(_order_conditional_variable[i]));
|
d = maxdim(d, GetStringBoundingBox(STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + _order_conditional_variable[i]));
|
||||||
}
|
}
|
||||||
d.width += padding.width;
|
d.width += padding.width;
|
||||||
d.height += padding.height;
|
d.height += padding.height;
|
||||||
|
@ -996,7 +998,7 @@ public:
|
||||||
}
|
}
|
||||||
OrderConditionVariable ocv = order->GetConditionVariable();
|
OrderConditionVariable ocv = order->GetConditionVariable();
|
||||||
/* Set the strings for the dropdown boxes. */
|
/* Set the strings for the dropdown boxes. */
|
||||||
this->GetWidget<NWidgetCore>(ORDER_WIDGET_COND_VARIABLE)->widget_data = _order_conditional_variable[order == NULL ? 0 : ocv];
|
this->GetWidget<NWidgetCore>(ORDER_WIDGET_COND_VARIABLE)->widget_data = STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + (order == NULL ? 0 : ocv);
|
||||||
this->GetWidget<NWidgetCore>(ORDER_WIDGET_COND_COMPARATOR)->widget_data = _order_conditional_condition[order == NULL ? 0 : order->GetConditionComparator()];
|
this->GetWidget<NWidgetCore>(ORDER_WIDGET_COND_COMPARATOR)->widget_data = _order_conditional_condition[order == NULL ? 0 : order->GetConditionComparator()];
|
||||||
this->SetWidgetDisabledState(ORDER_WIDGET_COND_COMPARATOR, ocv == OCV_UNCONDITIONALLY);
|
this->SetWidgetDisabledState(ORDER_WIDGET_COND_COMPARATOR, ocv == OCV_UNCONDITIONALLY);
|
||||||
this->SetWidgetDisabledState(ORDER_WIDGET_COND_VALUE, ocv == OCV_REQUIRES_SERVICE || ocv == OCV_UNCONDITIONALLY);
|
this->SetWidgetDisabledState(ORDER_WIDGET_COND_VALUE, ocv == OCV_REQUIRES_SERVICE || ocv == OCV_UNCONDITIONALLY);
|
||||||
|
@ -1225,9 +1227,14 @@ public:
|
||||||
ShowTimetableWindow(this->vehicle);
|
ShowTimetableWindow(this->vehicle);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ORDER_WIDGET_COND_VARIABLE:
|
case ORDER_WIDGET_COND_VARIABLE: {
|
||||||
ShowDropDownMenu(this, _order_conditional_variable, this->vehicle->GetOrder(this->OrderGetSel())->GetConditionVariable(), ORDER_WIDGET_COND_VARIABLE, 0, 0);
|
DropDownList *list = new DropDownList();
|
||||||
|
for (uint i = 0; i < lengthof(_order_conditional_variable); i++) {
|
||||||
|
list->push_back(new DropDownListStringItem(STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + _order_conditional_variable[i], _order_conditional_variable[i], false));
|
||||||
|
}
|
||||||
|
ShowDropDownList(this, list, this->vehicle->GetOrder(this->OrderGetSel())->GetConditionVariable(), ORDER_WIDGET_COND_VARIABLE);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case ORDER_WIDGET_COND_COMPARATOR: {
|
case ORDER_WIDGET_COND_COMPARATOR: {
|
||||||
const Order *o = this->vehicle->GetOrder(this->OrderGetSel());
|
const Order *o = this->vehicle->GetOrder(this->OrderGetSel());
|
||||||
|
@ -1264,6 +1271,7 @@ public:
|
||||||
case OCV_RELIABILITY:
|
case OCV_RELIABILITY:
|
||||||
case OCV_LOAD_PERCENTAGE:
|
case OCV_LOAD_PERCENTAGE:
|
||||||
value = Clamp(value, 0, 100);
|
value = Clamp(value, 0, 100);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -110,12 +110,13 @@ DECLARE_ENUM_AS_BIT_SET(OrderDepotActionFlags)
|
||||||
* Variables (of a vehicle) to 'cause' skipping on.
|
* Variables (of a vehicle) to 'cause' skipping on.
|
||||||
*/
|
*/
|
||||||
enum OrderConditionVariable {
|
enum OrderConditionVariable {
|
||||||
OCV_LOAD_PERCENTAGE, ///< Skip based on the amount of load
|
OCV_LOAD_PERCENTAGE, ///< Skip based on the amount of load
|
||||||
OCV_RELIABILITY, ///< Skip based on the reliability
|
OCV_RELIABILITY, ///< Skip based on the reliability
|
||||||
OCV_MAX_SPEED, ///< Skip based on the maximum speed
|
OCV_MAX_SPEED, ///< Skip based on the maximum speed
|
||||||
OCV_AGE, ///< Skip based on the age
|
OCV_AGE, ///< Skip based on the age
|
||||||
OCV_REQUIRES_SERVICE, ///< Skip when the vehicle requires service
|
OCV_REQUIRES_SERVICE, ///< Skip when the vehicle requires service
|
||||||
OCV_UNCONDITIONALLY, ///< Always skip
|
OCV_UNCONDITIONALLY, ///< Always skip
|
||||||
|
OCV_REMAINING_LIFETIME, ///< Skip based on the remaining lifetime
|
||||||
OCV_END
|
OCV_END
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue