Merge branch 'more_cond_orders-sx' into jgrpp

Conflicts:
	src/order_base.h
	src/order_gui.cpp
	src/saveload/extended_ver_sl.cpp
	src/saveload/extended_ver_sl.h
This commit is contained in:
Jonathan G Rennison
2015-08-26 23:24:41 +01:00
10 changed files with 329 additions and 13 deletions

View File

@@ -157,6 +157,10 @@ static const OrderConditionVariable _order_conditional_variable[] = {
OCV_AGE,
OCV_REMAINING_LIFETIME,
OCV_REQUIRES_SERVICE,
OCV_CARGO_WAITING,
OCV_CARGO_ACCEPTANCE,
OCV_FREE_PLATFORMS,
OCV_PERCENT,
OCV_UNCONDITIONALLY,
};
@@ -172,6 +176,30 @@ static const StringID _order_conditional_condition[] = {
INVALID_STRING_ID,
};
static const StringID _order_conditional_condition_has[] = {
STR_ORDER_CONDITIONAL_COMPARATOR_HAS,
STR_ORDER_CONDITIONAL_COMPARATOR_HAS_NO,
STR_ORDER_CONDITIONAL_COMPARATOR_HAS_LESS_THAN,
STR_ORDER_CONDITIONAL_COMPARATOR_HAS_LESS_EQUALS,
STR_ORDER_CONDITIONAL_COMPARATOR_HAS_MORE_THAN,
STR_ORDER_CONDITIONAL_COMPARATOR_HAS_MORE_EQUALS,
STR_ORDER_CONDITIONAL_COMPARATOR_HAS,
STR_ORDER_CONDITIONAL_COMPARATOR_HAS_NO,
INVALID_STRING_ID,
};
static const StringID _order_conditional_condition_accepts[] = {
STR_NULL,
STR_NULL,
STR_NULL,
STR_NULL,
STR_NULL,
STR_NULL,
STR_ORDER_CONDITIONAL_COMPARATOR_ACCEPTS,
STR_ORDER_CONDITIONAL_COMPARATOR_DOES_NOT_ACCEPT,
INVALID_STRING_ID,
};
extern uint ConvertSpeedToDisplaySpeed(uint speed);
extern uint ConvertDisplaySpeedToSpeed(uint speed);
@@ -327,19 +355,46 @@ void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int
SetDParam(1, order->GetDestination());
break;
case OT_CONDITIONAL:
case OT_CONDITIONAL: {
SetDParam(1, order->GetConditionSkipToOrder() + 1);
if (order->GetConditionVariable() == OCV_UNCONDITIONALLY) {
const OrderConditionVariable ocv = order->GetConditionVariable( );
/* handle some non-ordinary cases seperately */
if (ocv == OCV_UNCONDITIONALLY) {
SetDParam(0, STR_ORDER_CONDITIONAL_UNCONDITIONAL);
} else if (ocv == OCV_PERCENT) {
SetDParam(0, STR_CONDITIONAL_PERCENT);
SetDParam(2, order->GetConditionValue());
} else if (ocv == OCV_FREE_PLATFORMS) {
SetDParam(0, STR_CONDITIONAL_FREE_PLATFORMS );
SetDParam(2, STR_ORDER_CONDITIONAL_COMPARATOR_HAS + order->GetConditionComparator());
SetDParam(3, order->GetConditionValue());
} else {
OrderConditionComparator occ = order->GetConditionComparator();
SetDParam(0, (occ == OCC_IS_TRUE || occ == OCC_IS_FALSE) ? STR_ORDER_CONDITIONAL_TRUE_FALSE : STR_ORDER_CONDITIONAL_NUM);
SetDParam(2, STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + order->GetConditionVariable());
SetDParam(3, STR_ORDER_CONDITIONAL_COMPARATOR_EQUALS + occ);
bool is_cargo = ocv == OCV_CARGO_ACCEPTANCE || ocv == OCV_CARGO_WAITING;
SetDParam(0, is_cargo ? STR_ORDER_CONDITIONAL_CARGO : (occ == OCC_IS_TRUE || occ == OCC_IS_FALSE) ? STR_ORDER_CONDITIONAL_TRUE_FALSE : STR_ORDER_CONDITIONAL_NUM);
SetDParam(2, (ocv == OCV_CARGO_ACCEPTANCE || ocv == OCV_CARGO_WAITING || ocv == OCV_FREE_PLATFORMS)
? STR_ORDER_CONDITIONAL_NEXT_STATION : STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + ocv);
uint value = order->GetConditionValue();
if (order->GetConditionVariable() == OCV_MAX_SPEED) value = ConvertSpeedToDisplaySpeed(value);
SetDParam(4, value);
switch (ocv) {
case OCV_CARGO_ACCEPTANCE:
SetDParam(3, STR_ORDER_CONDITIONAL_COMPARATOR_ACCEPTS + occ - OCC_IS_TRUE);
SetDParam(4, CargoSpec::Get( value )->name );
break;
case OCV_CARGO_WAITING:
SetDParam(3, STR_ORDER_CONDITIONAL_COMPARATOR_HAS + occ - OCC_IS_TRUE);
SetDParam(4, CargoSpec::Get( value )->name );
break;
case OCV_REQUIRES_SERVICE:
SetDParam(3, STR_ORDER_CONDITIONAL_COMPARATOR_EQUALS + occ);
break;
case OCV_MAX_SPEED:
value = ConvertSpeedToDisplaySpeed(value);
/* FALL THROUGH */
default:
SetDParam(3, STR_ORDER_CONDITIONAL_COMPARATOR_EQUALS + occ);
SetDParam(4, value);
}
}
if (timetable && order->GetWaitTime() > 0) {
@@ -348,7 +403,9 @@ void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int
} else {
SetDParam(5, STR_EMPTY);
}
break;
}
default: NOT_REACHED();
}
@@ -509,6 +566,11 @@ private:
/* WID_O_SEL_TOP_ROW */
DP_ROW_LOAD = 0, ///< Display 'load' / 'unload' / 'refit' buttons in the top row of the ship/airplane order window.
DP_ROW_DEPOT = 1, ///< Display 'refit' / 'service' buttons in the top row of the ship/airplane order window.
/* WID_O_SEL_COND_VALUE */
DP_COND_VALUE_NUMBER = 0, ///< Display number widget
DP_COND_VALUE_CARGO = 1, ///< Display dropdown widget cargo types
DP_ROW_CONDITIONAL = 2, ///< Display the conditional order buttons in the top row of the ship/airplane order window.
/* WID_O_SEL_BOTTOM_MIDDLE */
@@ -523,6 +585,8 @@ private:
Scrollbar *vscroll;
bool can_do_refit; ///< Vehicle chain can be refitted in depot.
bool can_do_autorefit; ///< Vehicle chain can be auto-refitted.
StringID cargo_names_list[NUM_CARGO + 1];
uint32 cargo_bitmask;
/**
* Return the memorised selected order.
@@ -555,6 +619,28 @@ private:
return (sel <= vehicle->GetNumOrders() && sel >= 0) ? sel : INVALID_VEH_ORDER_ID;
}
/**
* Determine which strings should be displayed in the conditional comparator dropdown
*
* @param order the order to evaluate
* @return the StringIDs to display
*/
static const StringID *GetComparatorStrings(const Order *order)
{
if (order == NULL) return _order_conditional_condition;
switch (order->GetConditionVariable()) {
case OCV_FREE_PLATFORMS:
case OCV_CARGO_WAITING:
return _order_conditional_condition_has;
case OCV_CARGO_ACCEPTANCE:
return _order_conditional_condition_accepts;
default:
return _order_conditional_condition;
}
}
/**
* Handle the click on the goto button.
*/
@@ -851,6 +937,18 @@ public:
break;
}
}
/* Create cargo bitmask */
assert_compile(NUM_CARGO <= 32);
for (CargoID c = 0; c < NUM_CARGO; c++) {
if (CargoSpec::Get(c)->IsValid()) {
this->cargo_names_list[c] = CargoSpec::Get(c)->name;
SetBit(this->cargo_bitmask, c);
}
}
this->cargo_bitmask = ~this->cargo_bitmask;
this->cargo_names_list[NUM_CARGO] = INVALID_STRING_ID;
}
/**
@@ -1061,11 +1159,20 @@ public:
} else {
train_row_sel->SetDisplayedPlane(DP_GROUNDVEHICLE_ROW_CONDITIONAL);
}
OrderConditionVariable ocv = order->GetConditionVariable();
OrderConditionVariable ocv = (order == NULL) ? OCV_LOAD_PERCENTAGE : order->GetConditionVariable();
bool is_cargo = (ocv == OCV_CARGO_ACCEPTANCE || ocv == OCV_CARGO_WAITING);
if (is_cargo) {
this->GetWidget<NWidgetCore>(WID_O_COND_CARGO)->widget_data = cargo_names_list[(order == NULL) ? 0 : order->GetConditionValue()];
this->GetWidget<NWidgetStacked>(WID_O_SEL_COND_VALUE)->SetDisplayedPlane(DP_COND_VALUE_CARGO);
} else {
this->GetWidget<NWidgetStacked>(WID_O_SEL_COND_VALUE)->SetDisplayedPlane(DP_COND_VALUE_NUMBER);
}
/* Set the strings for the dropdown boxes. */
this->GetWidget<NWidgetCore>(WID_O_COND_VARIABLE)->widget_data = STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + ocv;
this->GetWidget<NWidgetCore>(WID_O_COND_COMPARATOR)->widget_data = _order_conditional_condition[order->GetConditionComparator()];
this->SetWidgetDisabledState(WID_O_COND_COMPARATOR, ocv == OCV_UNCONDITIONALLY);
this->GetWidget<NWidgetCore>(WID_O_COND_COMPARATOR)->widget_data = GetComparatorStrings(order)[order->GetConditionComparator()];
this->SetWidgetDisabledState(WID_O_COND_COMPARATOR, ocv == OCV_UNCONDITIONALLY || ocv == OCV_PERCENT);
this->SetWidgetDisabledState(WID_O_COND_VALUE, ocv == OCV_REQUIRES_SERVICE || ocv == OCV_UNCONDITIONALLY);
break;
}
@@ -1352,6 +1459,12 @@ public:
}
break;
case WID_O_COND_CARGO: {
uint value = this->vehicle->GetOrder(this->OrderGetSel())->GetConditionValue();
ShowDropDownMenu(this, cargo_names_list, value, WID_O_COND_CARGO, 0, cargo_bitmask);
break;
}
case WID_O_TIMETABLE_VIEW:
ShowTimetableWindow(this->vehicle);
break;
@@ -1367,7 +1480,9 @@ public:
case WID_O_COND_COMPARATOR: {
const Order *o = this->vehicle->GetOrder(this->OrderGetSel());
ShowDropDownMenu(this, _order_conditional_condition, o->GetConditionComparator(), WID_O_COND_COMPARATOR, 0, (o->GetConditionVariable() == OCV_REQUIRES_SERVICE) ? 0x3F : 0xC0, 0, DDSF_LOST_FOCUS);
OrderConditionVariable cond_var = o->GetConditionVariable();
ShowDropDownMenu(this, GetComparatorStrings(o), o->GetConditionComparator(), WID_O_COND_COMPARATOR, 0,
(cond_var == OCV_REQUIRES_SERVICE || cond_var == OCV_CARGO_ACCEPTANCE || cond_var == OCV_CARGO_WAITING) ? 0x3F : 0xC0, 0, DDSF_LOST_FOCUS);
break;
}
@@ -1403,6 +1518,7 @@ public:
value = ConvertDisplaySpeedToSpeed(value);
break;
case OCV_PERCENT:
case OCV_RELIABILITY:
case OCV_LOAD_PERCENTAGE:
value = Clamp(value, 0, 100);
@@ -1455,6 +1571,10 @@ public:
case WID_O_COND_COMPARATOR:
DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 20), MOF_COND_COMPARATOR | index << 4, CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
break;
case WID_O_COND_CARGO:
DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 20), MOF_COND_VALUE | index << 4, CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
break;
}
}
@@ -1672,8 +1792,12 @@ static const NWidgetPart _nested_orders_train_widgets[] = {
SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_VARIABLE_TOOLTIP), SetResize(1, 0),
NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_O_COND_COMPARATOR), SetMinimalSize(124, 12), SetFill(1, 0),
SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_COMPARATOR_TOOLTIP), SetResize(1, 0),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_COND_VALUE), SetMinimalSize(124, 12), SetFill(1, 0),
NWidget(NWID_SELECTION, INVALID_COLOUR, WID_O_SEL_COND_VALUE),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_O_COND_VALUE), SetMinimalSize(124, 12), SetFill(1, 0),
SetDataTip(STR_BLACK_COMMA, STR_ORDER_CONDITIONAL_VALUE_TOOLTIP), SetResize(1, 0),
NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_O_COND_CARGO), SetMinimalSize(124, 12), SetFill(1, 0),
SetDataTip(STR_NULL, STR_ORDER_CONDITIONAL_CARGO_TOOLTIP), SetResize(1, 0),
EndContainer(),
EndContainer(),
EndContainer(),
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_O_OCCUPANCY_TOGGLE), SetMinimalSize(12, 12), SetDataTip(STR_ORDERS_OCCUPANCY_BUTTON, STR_ORDERS_OCCUPANCY_BUTTON_TOOLTIP),