order_cmd.c
changeset 1053 8d90844ddc2e
parent 1043 44508ede2f92
child 1055 cc4f60cc9102
equal deleted inserted replaced
1052:f996874f0f16 1053:8d90844ddc2e
   627 /**
   627 /**
   628  *
   628  *
   629  * Check the orders of a vehicle, to see if there are invalid orders and stuff
   629  * Check the orders of a vehicle, to see if there are invalid orders and stuff
   630  *
   630  *
   631  */
   631  */
   632 bool CheckOrders(const Vehicle *v)
   632 bool CheckOrders(uint data_a, uint data_b)
   633 {
   633 {
       
   634 	Vehicle *v = GetVehicle(data_a);
   634 	/* Does the user wants us to check things? */
   635 	/* Does the user wants us to check things? */
   635 	if (_patches.order_review_system == 0)
   636 	if (_patches.order_review_system == 0)
   636 		return false;
   637 		return false;
   637 
   638 
   638 	/* Do nothing for crashed vehicles */
   639 	/* Do nothing for crashed vehicles */
   639 	if(v->vehstatus & VS_CRASHED)
   640 	if(v->vehstatus & VS_CRASHED)
   640 		return false;
   641 		return false;
   641 
   642 
   642 	/* Do nothing for stopped vehicles if setting is '1' */
   643 	/* Do nothing for stopped vehicles if setting is '1' */
   643 	if ( (_patches.order_review_system == 1) && (v->vehstatus & VS_STOPPED) )
   644 	if ( (_patches.order_review_system == 1) && (v->vehstatus & VS_STOPPED) )
       
   645 		return false;
       
   646 
       
   647 	/* do nothing we we're not the first vehicle in a share-chain */
       
   648 	if (v->next_shared != NULL)
   644 		return false;
   649 		return false;
   645 
   650 
   646 	/* Only check every 20 days, so that we don't flood the message log */
   651 	/* Only check every 20 days, so that we don't flood the message log */
   647 	if ( ( ( v->day_counter % 20) == 0 ) && (v->owner == _local_player) ) {
   652 	if ( ( ( v->day_counter % 20) == 0 ) && (v->owner == _local_player) ) {
   648 		int n_st, problem_type = -1;
   653 		int n_st, problem_type = -1;
   651 		int message = 0;
   656 		int message = 0;
   652 
   657 
   653 		/* Check the order list */
   658 		/* Check the order list */
   654 		n_st = 0;
   659 		n_st = 0;
   655 
   660 
       
   661 		/*if (data_b == OC_INIT) {
       
   662 			DEBUG(misc, 3) ("CheckOrder called in mode 0 (initiation mode) for %d", v->index);
       
   663 		} else {
       
   664 			DEBUG(misc, 3) ("CheckOrder called in mode 1 (validation mode) for %d", v->index);
       
   665 		}*/
       
   666 		
   656 		FOR_VEHICLE_ORDERS(v, order) {
   667 		FOR_VEHICLE_ORDERS(v, order) {
   657 			/* Dummy order? */
   668 			/* Dummy order? */
   658 			if (order->type == OT_DUMMY) {
   669 			if (order->type == OT_DUMMY) {
   659 				problem_type = 1;
   670 				problem_type = 1;
   660 				break;
   671 				break;
   681 		/* Do we only have 1 station in our order list? */
   692 		/* Do we only have 1 station in our order list? */
   682 		if ((n_st < 2) && (problem_type == -1))
   693 		if ((n_st < 2) && (problem_type == -1))
   683 			problem_type = 0;
   694 			problem_type = 0;
   684 
   695 
   685 		/* We don't have a problem */
   696 		/* We don't have a problem */
   686 		if (problem_type < 0)
   697 		if (problem_type < 0) {
       
   698 			/*if (data_b == OC_INIT) {
       
   699 				DEBUG(misc, 3) ("CheckOrder mode 0: no problems found for %d", v->index);
       
   700 			} else {
       
   701 				DEBUG(misc, 3) ("CheckOrder mode 1: news item surpressed for %d", v->index);
       
   702 			}*/
   687 			return false;
   703 			return false;
       
   704 		}
       
   705 
       
   706 		/* we have a problem, are we're just in the validation process
       
   707 		   so don't display an error message */
       
   708 		if (data_b == OC_VALIDATE) {
       
   709 			/*DEBUG(misc, 3) ("CheckOrder mode 1: new item validated for %d", v->index);*/
       
   710 			return true;
       
   711 		}
   688 
   712 
   689 		message = (STR_TRAIN_HAS_TOO_FEW_ORDERS) + (((v->type) - VEH_Train) << 2) + problem_type;
   713 		message = (STR_TRAIN_HAS_TOO_FEW_ORDERS) + (((v->type) - VEH_Train) << 2) + problem_type;
       
   714 		/*DEBUG(misc, 3) ("Checkorder mode 0: Triggered News Item for %d", v->index);*/
   690 
   715 
   691 		SetDParam(0, v->unitnumber);
   716 		SetDParam(0, v->unitnumber);
   692 		AddNewsItem(
   717 		AddValidatedNewsItem(
   693 			message,
   718 			message,
   694 			NEWS_FLAGS(NM_SMALL, NF_VIEWPORT | NF_VEHICLE, NT_ADVICE, 0),
   719 			NEWS_FLAGS(NM_SMALL, NF_VIEWPORT | NF_VEHICLE, NT_ADVICE, 0),
   695 			v->index,
   720 			v->index,
   696 			0);
   721 			OC_VALIDATE,	//next time, just validate the orders
       
   722 			CheckOrders);
   697 	}
   723 	}
   698 
   724 
   699 	return true;
   725 	return true;
   700 }
   726 }
   701 
   727