src/order_cmd.cpp
changeset 9665 dd6c07db9d32
parent 9641 a854c7cf6af5
child 9666 fa2ee5ae35b5
equal deleted inserted replaced
9664:469dad45a4d3 9665:dd6c07db9d32
   373 			}
   373 			}
   374 
   374 
   375 			/* Non stop not allowed for non-trains. */
   375 			/* Non stop not allowed for non-trains. */
   376 			if (new_order.GetNonStopType() != ONSF_STOP_EVERYWHERE && v->type != VEH_TRAIN && v->type != VEH_ROAD) return CMD_ERROR;
   376 			if (new_order.GetNonStopType() != ONSF_STOP_EVERYWHERE && v->type != VEH_TRAIN && v->type != VEH_ROAD) return CMD_ERROR;
   377 
   377 
   378 			/* Full load and unload are mutual exclusive. */
   378 			/* No load and no unload are mutual exclusive. */
   379 			if ((new_order.GetLoadType() & OLFB_FULL_LOAD) && (new_order.GetUnloadType() & OUFB_UNLOAD)) return CMD_ERROR;
   379 			if ((new_order.GetLoadType() & OLFB_NO_LOAD) && (new_order.GetUnloadType() & OUFB_NO_UNLOAD)) return CMD_ERROR;
   380 
   380 
   381 			/* Filter invalid load/unload types. */
   381 			/* Filter invalid load/unload types. */
   382 			switch (new_order.GetLoadType()) {
   382 			switch (new_order.GetLoadType()) {
   383 				case OLF_LOAD_IF_POSSIBLE: case OLFB_FULL_LOAD: case OLF_FULL_LOAD_ANY: case OLFB_NO_LOAD: break;
   383 				case OLF_LOAD_IF_POSSIBLE: case OLFB_FULL_LOAD: case OLF_FULL_LOAD_ANY: case OLFB_NO_LOAD: break;
   384 				default: return CMD_ERROR;
   384 				default: return CMD_ERROR;
   435 			if (new_order.GetDepotActionType() & ~ODATFB_NEAREST_DEPOT) return CMD_ERROR;
   435 			if (new_order.GetDepotActionType() & ~ODATFB_NEAREST_DEPOT) return CMD_ERROR;
   436 			break;
   436 			break;
   437 		}
   437 		}
   438 
   438 
   439 		case OT_GOTO_WAYPOINT: {
   439 		case OT_GOTO_WAYPOINT: {
   440 
       
   441 			if (v->type != VEH_TRAIN) return CMD_ERROR;
   440 			if (v->type != VEH_TRAIN) return CMD_ERROR;
   442 
   441 
   443 			if (!IsValidWaypointID(new_order.GetDestination())) return CMD_ERROR;
   442 			if (!IsValidWaypointID(new_order.GetDestination())) return CMD_ERROR;
   444 			const Waypoint *wp = GetWaypoint(new_order.GetDestination());
   443 			const Waypoint *wp = GetWaypoint(new_order.GetDestination());
   445 
   444 
   451 			if (new_order.GetNonStopType() != ONSF_STOP_EVERYWHERE && v->type != VEH_TRAIN) return CMD_ERROR;
   450 			if (new_order.GetNonStopType() != ONSF_STOP_EVERYWHERE && v->type != VEH_TRAIN) return CMD_ERROR;
   452 			break;
   451 			break;
   453 		}
   452 		}
   454 
   453 
   455 		case OT_CONDITIONAL: {
   454 		case OT_CONDITIONAL: {
   456 			if (!IsPlayerBuildableVehicleType(v)) return CMD_ERROR;
       
   457 
       
   458 			VehicleOrderID skip_to = new_order.GetConditionSkipToOrder();
   455 			VehicleOrderID skip_to = new_order.GetConditionSkipToOrder();
   459 			if (skip_to >= v->num_orders) return CMD_ERROR;
   456 			if (skip_to != 0 && skip_to >= v->num_orders) {printf("%i: %i\n", skip_to, __LINE__); return CMD_ERROR;} // Always allow jumping to the first (even when there is no order).
   460 			if (new_order.GetNonStopType() != ONSF_STOP_EVERYWHERE) return CMD_ERROR;
   457 			if (new_order.GetConditionVariable() > OCV_END) {printf("%i\n", __LINE__); return CMD_ERROR;}
       
   458 
       
   459 			OrderConditionComparator occ = new_order.GetConditionComparator();
       
   460 			if (occ > OCC_END) {printf("%i\n", __LINE__); return CMD_ERROR;}
       
   461 			switch (new_order.GetConditionVariable()) {
       
   462 				case OCV_REQUIRES_SERVICE:
       
   463 					if (occ != OCC_IS_TRUE && occ != OCC_IS_FALSE) {printf("%i\n", __LINE__); return CMD_ERROR;}
       
   464 					break;
       
   465 
       
   466 				case OCV_UNCONDITIONALLY:
       
   467 					if (occ != OCC_EQUALS) {printf("%i\n", __LINE__); return CMD_ERROR;}
       
   468 					if (new_order.GetConditionValue() != 0) {printf("%i\n", __LINE__); return CMD_ERROR;}
       
   469 					break;
       
   470 
       
   471 				case OCV_LOAD_PERCENTAGE:
       
   472 				case OCV_RELIABILITY:
       
   473 					if (new_order.GetConditionValue() > 100) {printf("%i\n", __LINE__); return CMD_ERROR;}
       
   474 					/* FALL THROUGH */
       
   475 				default:
       
   476 					if (occ == OCC_IS_TRUE || occ == OCC_IS_FALSE) {printf("%i\n", __LINE__); return CMD_ERROR;}
       
   477 					break;
       
   478 			}
   461 		} break;
   479 		} break;
   462 
   480 
   463 		default: return CMD_ERROR;
   481 		default: return CMD_ERROR;
   464 	}
   482 	}
   465 
   483 
   936 				default:
   954 				default:
   937 					if (data > 2047) return CMD_ERROR;
   955 					if (data > 2047) return CMD_ERROR;
   938 					break;
   956 					break;
   939 			}
   957 			}
   940 			break;
   958 			break;
       
   959 
       
   960 		case MOF_COND_DESTINATION:
       
   961 			if (data >= v->num_orders) return CMD_ERROR;
       
   962 			break;
   941 	}
   963 	}
   942 
   964 
   943 	if (flags & DC_EXEC) {
   965 	if (flags & DC_EXEC) {
   944 		switch (mof) {
   966 		switch (mof) {
   945 			case MOF_NON_STOP:
   967 			case MOF_NON_STOP:
   993 				order->SetConditionComparator((OrderConditionComparator)data);
  1015 				order->SetConditionComparator((OrderConditionComparator)data);
   994 				break;
  1016 				break;
   995 
  1017 
   996 			case MOF_COND_VALUE:
  1018 			case MOF_COND_VALUE:
   997 				order->SetConditionValue(data);
  1019 				order->SetConditionValue(data);
       
  1020 				break;
       
  1021 
       
  1022 			case MOF_COND_DESTINATION:
       
  1023 				order->SetConditionSkipToOrder(data);
   998 				break;
  1024 				break;
   999 
  1025 
  1000 			default: NOT_REACHED();
  1026 			default: NOT_REACHED();
  1001 		}
  1027 		}
  1002 
  1028 
  1278 		/* CMD_NO_TEST_IF_IN_NETWORK is used here, because CMD_INSERT_ORDER checks if the
  1304 		/* CMD_NO_TEST_IF_IN_NETWORK is used here, because CMD_INSERT_ORDER checks if the
  1279 		 *  order number is one more than the current amount of orders, and because
  1305 		 *  order number is one more than the current amount of orders, and because
  1280 		 *  in network the commands are queued before send, the second insert always
  1306 		 *  in network the commands are queued before send, the second insert always
  1281 		 *  fails in test mode. By bypassing the test-mode, that no longer is a problem. */
  1307 		 *  fails in test mode. By bypassing the test-mode, that no longer is a problem. */
  1282 		for (uint i = 0; bak->order[i].IsValid(); i++) {
  1308 		for (uint i = 0; bak->order[i].IsValid(); i++) {
  1283 			if (!DoCommandP(0, v->index + (i << 16), bak->order[i].Pack(), NULL,
  1309 			Order o = bak->order[i];
       
  1310 			/* Conditional orders need to have their destination to be valid on insertion. */
       
  1311 			if (o.IsType(OT_CONDITIONAL)) o.SetConditionSkipToOrder(0);
       
  1312 
       
  1313 			if (!DoCommandP(0, v->index + (i << 16), o.Pack(), NULL,
  1284 					CMD_INSERT_ORDER | CMD_NO_TEST_IF_IN_NETWORK)) {
  1314 					CMD_INSERT_ORDER | CMD_NO_TEST_IF_IN_NETWORK)) {
       
  1315 				printf("huh?\n");
  1285 				break;
  1316 				break;
  1286 			}
  1317 			}
  1287 
  1318 
  1288 			/* Copy timetable if enabled */
  1319 			/* Copy timetable if enabled */
  1289 			if (_settings_game.order.timetabling && !DoCommandP(0, v->index | (i << 16) | (1 << 25),
  1320 			if (_settings_game.order.timetabling && !DoCommandP(0, v->index | (i << 16) | (1 << 25),
  1290 					bak->order[i].wait_time << 16 | bak->order[i].travel_time, NULL,
  1321 					o.wait_time << 16 | o.travel_time, NULL,
  1291 					CMD_CHANGE_TIMETABLE | CMD_NO_TEST_IF_IN_NETWORK)) {
  1322 					CMD_CHANGE_TIMETABLE | CMD_NO_TEST_IF_IN_NETWORK)) {
       
  1323 				printf("umh?\n");
       
  1324 				break;
       
  1325 			}
       
  1326 		}
       
  1327 
       
  1328 			/* Fix the conditional orders' destination. */
       
  1329 		for (uint i = 0; bak->order[i].IsValid(); i++) {
       
  1330 			if (!bak->order[i].IsType(OT_CONDITIONAL)) continue;
       
  1331 
       
  1332 			if (!DoCommandP(0, v->index + (i << 16), MOF_LOAD | (bak->order[i].GetConditionSkipToOrder() << 4), NULL,
       
  1333 					CMD_MODIFY_ORDER | CMD_NO_TEST_IF_IN_NETWORK)) {
  1292 				break;
  1334 				break;
  1293 			}
  1335 			}
  1294 		}
  1336 		}
  1295 	}
  1337 	}
  1296 
  1338