src/ai/trolly/shared.cpp
changeset 10207 c291a21b304e
parent 9111 48ce04029fe4
child 10208 72c00af5c95d
equal deleted inserted replaced
10206:0050610c0368 10207:c291a21b304e
    76 }
    76 }
    77 
    77 
    78 
    78 
    79 // This functions looks up if this vehicle is special for this AI
    79 // This functions looks up if this vehicle is special for this AI
    80 //  and returns his flag
    80 //  and returns his flag
    81 uint AiNew_GetSpecialVehicleFlag(Player* p, Vehicle* v)
    81 uint AiNew_GetSpecialVehicleFlag(Company *c, Vehicle *v)
    82 {
    82 {
    83 	uint i;
    83 	uint i;
    84 
    84 
    85 	for (i = 0; i < AI_MAX_SPECIAL_VEHICLES; i++) {
    85 	for (i = 0; i < AI_MAX_SPECIAL_VEHICLES; i++) {
    86 		if (_players_ainew[p->index].special_vehicles[i].veh_id == v->index) {
    86 		if (_companies_ainew[c->index].special_vehicles[i].veh_id == v->index) {
    87 			return _players_ainew[p->index].special_vehicles[i].flag;
    87 			return _companies_ainew[c->index].special_vehicles[i].flag;
    88 		}
    88 		}
    89 	}
    89 	}
    90 
    90 
    91 	// Not found :(
    91 	// Not found :(
    92 	return 0;
    92 	return 0;
    93 }
    93 }
    94 
    94 
    95 
    95 
    96 bool AiNew_SetSpecialVehicleFlag(Player* p, Vehicle* v, uint flag)
    96 bool AiNew_SetSpecialVehicleFlag(Company *c, Vehicle *v, uint flag)
    97 {
    97 {
    98 	int new_id = -1;
    98 	int new_id = -1;
    99 	uint i;
    99 	uint i;
   100 
   100 
   101 	for (i = 0; i < AI_MAX_SPECIAL_VEHICLES; i++) {
   101 	for (i = 0; i < AI_MAX_SPECIAL_VEHICLES; i++) {
   102 		if (_players_ainew[p->index].special_vehicles[i].veh_id == v->index) {
   102 		if (_companies_ainew[c->index].special_vehicles[i].veh_id == v->index) {
   103 			_players_ainew[p->index].special_vehicles[i].flag |= flag;
   103 			_companies_ainew[c->index].special_vehicles[i].flag |= flag;
   104 			return true;
   104 			return true;
   105 		}
   105 		}
   106 		if (new_id == -1 &&
   106 		if (new_id == -1 &&
   107 				_players_ainew[p->index].special_vehicles[i].veh_id == 0 &&
   107 				_companies_ainew[c->index].special_vehicles[i].veh_id == 0 &&
   108 				_players_ainew[p->index].special_vehicles[i].flag == 0) {
   108 				_companies_ainew[c->index].special_vehicles[i].flag == 0) {
   109 			new_id = i;
   109 			new_id = i;
   110 		}
   110 		}
   111 	}
   111 	}
   112 
   112 
   113 	// Out of special_vehicle spots :s
   113 	// Out of special_vehicle spots :s
   114 	if (new_id == -1) {
   114 	if (new_id == -1) {
   115 		DEBUG(ai, 1, "special_vehicles list is too small");
   115 		DEBUG(ai, 1, "special_vehicles list is too small");
   116 		return false;
   116 		return false;
   117 	}
   117 	}
   118 	_players_ainew[p->index].special_vehicles[new_id].veh_id = v->index;
   118 	_companies_ainew[c->index].special_vehicles[new_id].veh_id = v->index;
   119 	_players_ainew[p->index].special_vehicles[new_id].flag = flag;
   119 	_companies_ainew[c->index].special_vehicles[new_id].flag = flag;
   120 	return true;
   120 	return true;
   121 }
   121 }