Import more conditional orders patch

http://www.tt-forums.net/viewtopic.php?p=1033223#p1033223
This commit is contained in:
patch-import
2015-08-26 22:19:35 +01:00
committed by Jonathan G Rennison
parent 789266146f
commit c757a97214
10 changed files with 327 additions and 14 deletions

View File

@@ -153,6 +153,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,
};
@@ -168,6 +172,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);
@@ -316,20 +344,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);
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->wait_time > 0) {
SetDParam(5, STR_TIMETABLE_AND_TRAVEL_FOR);
@@ -337,6 +391,7 @@ void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int
} else {
SetDParam(5, STR_EMPTY);
}
}
break;
default: NOT_REACHED();
@@ -506,6 +561,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 */
@@ -519,6 +579,8 @@ private:
const Vehicle *vehicle; ///< Vehicle owning the orders being displayed and manipulated.
Scrollbar *vscroll;
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.
@@ -551,6 +613,23 @@ 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: //fall through
case OCV_CARGO_WAITING: return _order_conditional_condition_has; break;
case OCV_CARGO_ACCEPTANCE: return _order_conditional_condition_accepts; break;
default: return _order_conditional_condition; break;
}
}
/**
* Handle the click on the goto button.
* @param i Dummy parameter.
@@ -853,6 +932,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;
}
/**
@@ -1054,11 +1145,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 + (order == NULL ? 0 : ocv);
this->GetWidget<NWidgetCore>(WID_O_COND_COMPARATOR)->widget_data = _order_conditional_condition[order == NULL ? 0 : order->GetConditionComparator()];
this->SetWidgetDisabledState(WID_O_COND_COMPARATOR, ocv == OCV_UNCONDITIONALLY);
this->GetWidget<NWidgetCore>(WID_O_COND_COMPARATOR)->widget_data = GetComparatorStrings(order)[order == NULL ? 0 : 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;
}
@@ -1291,6 +1391,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;
@@ -1306,7 +1412,11 @@ 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);
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);
break;
}
@@ -1336,6 +1446,7 @@ public:
value = ConvertDisplaySpeedToSpeed(value);
break;
case OCV_PERCENT:
case OCV_RELIABILITY:
case OCV_LOAD_PERCENTAGE:
value = Clamp(value, 0, 100);
@@ -1388,6 +1499,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;
}
}
@@ -1579,10 +1694,14 @@ 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(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_PUSHIMGBTN, COLOUR_GREY, WID_O_SHARED_ORDER_LIST), SetMinimalSize(12, 12), SetDataTip(SPR_SHARED_ORDERS_ICON, STR_ORDERS_VEH_WITH_SHARED_ORDERS_LIST_TOOLTIP),
EndContainer(),