ai.c
changeset 568 b0d0df062880
parent 558 1ae2a752501e
child 679 04ca2cd69420
equal deleted inserted replaced
567:e63b977925f7 568:b0d0df062880
  1528 static bool AiCheckTrackResources(TileIndex tile, const AiDefaultBlockData *p, byte cargo)
  1528 static bool AiCheckTrackResources(TileIndex tile, const AiDefaultBlockData *p, byte cargo)
  1529 {
  1529 {
  1530 	uint values[NUM_CARGO];
  1530 	uint values[NUM_CARGO];
  1531 	int w,h;
  1531 	int w,h;
  1532 	uint tile2;
  1532 	uint tile2;
       
  1533 	int rad;
  1533 
  1534 
  1534 	for(;p->mode != 4;p++) if (p->mode == 1) {
  1535 	for(;p->mode != 4;p++) if (p->mode == 1) {
  1535 		tile2 = TILE_ADD(tile, p->tileoffs);
  1536 		tile2 = TILE_ADD(tile, p->tileoffs);
  1536 
  1537 
  1537 		w = ((p->attr>>1) & 7);
  1538 		w = ((p->attr>>1) & 7);
  1538 		h = ((p->attr>>4) & 7);
  1539 		h = ((p->attr>>4) & 7);
  1539 		if (p->attr&1) intswap(w, h);
  1540 		if (p->attr&1) intswap(w, h);
  1540 
  1541 
       
  1542 
       
  1543 		if (_patches.modified_catchment) {
       
  1544 			rad = CA_TRAIN;
       
  1545 		} else {
       
  1546 			rad = 4;
       
  1547 		}
       
  1548 
  1541 		if (cargo & 0x80) {
  1549 		if (cargo & 0x80) {
  1542 			GetProductionAroundTiles(values, tile2, w, h);
  1550 			GetProductionAroundTiles(values, tile2, w, h, rad);
  1543 			return values[cargo & 0x7F] != 0;
  1551 			return values[cargo & 0x7F] != 0;
  1544 		} else {
  1552 		} else {
  1545 			GetAcceptanceAroundTiles(values, tile2, w, h);
  1553 			GetAcceptanceAroundTiles(values, tile2, w, h, rad);
  1546 			if (!(values[cargo] & ~7))
  1554 			if (!(values[cargo] & ~7))
  1547 				return false;
  1555 				return false;
  1548 			if (cargo != CT_MAIL)
  1556 			if (cargo != CT_MAIL)
  1549 				return true;
  1557 				return true;
  1550 			return !!((values[cargo]>>1) & ~7);
  1558 			return !!((values[cargo]>>1) & ~7);
  2470 }
  2478 }
  2471 
  2479 
  2472 static bool AiCheckRoadResources(TileIndex tile, const AiDefaultBlockData *p, byte cargo)
  2480 static bool AiCheckRoadResources(TileIndex tile, const AiDefaultBlockData *p, byte cargo)
  2473 {
  2481 {
  2474 	uint values[NUM_CARGO];
  2482 	uint values[NUM_CARGO];
       
  2483 	int rad;
       
  2484 	
       
  2485 	if (_patches.modified_catchment) {
       
  2486 		rad = CA_TRUCK;		//Same as CA_BUS at the moment? 
       
  2487 	} else {			//change that at some point?
       
  2488 		rad = 4;
       
  2489 	}
       
  2490 	
  2475 	for(;;p++) {
  2491 	for(;;p++) {
  2476 		if (p->mode == 4) {
  2492 		if (p->mode == 4) {
  2477 			return true;
  2493 			return true;
  2478 		} else if (p->mode == 1) {
  2494 		} else if (p->mode == 1) {
  2479 			uint tile2 = TILE_ADD(tile, p->tileoffs);
  2495 			uint tile2 = TILE_ADD(tile, p->tileoffs);
  2480 			if (cargo & 0x80) {
  2496 			if (cargo & 0x80) {
  2481 				GetProductionAroundTiles(values, tile2, 1, 1);
  2497 				GetProductionAroundTiles(values, tile2, 1, 1, rad);
  2482 				return values[cargo & 0x7F] != 0;
  2498 				return values[cargo & 0x7F] != 0;
  2483 			} else {
  2499 			} else {
  2484 				GetAcceptanceAroundTiles(values, tile2, 1, 1);
  2500 				GetAcceptanceAroundTiles(values, tile2, 1, 1, rad);
  2485 				return (values[cargo]&~7) != 0;
  2501 				return (values[cargo]&~7) != 0;
  2486 			}
  2502 			}
  2487 		}
  2503 		}
  2488 	}
  2504 	}
  2489 }
  2505 }
  3334 static bool AiCheckAirportResources(TileIndex tile, const AiDefaultBlockData *p, byte cargo)
  3350 static bool AiCheckAirportResources(TileIndex tile, const AiDefaultBlockData *p, byte cargo)
  3335 {
  3351 {
  3336 	uint values[NUM_CARGO];
  3352 	uint values[NUM_CARGO];
  3337 	int w,h;
  3353 	int w,h;
  3338 	uint tile2;
  3354 	uint tile2;
       
  3355 	int rad;
       
  3356 	
       
  3357 	if (_patches.modified_catchment) {
       
  3358 		rad = CA_AIR_LARGE;		//I Have NFI what airport the 
       
  3359 	} else {				//AI is going to build here
       
  3360 		rad = 4;
       
  3361 	}
  3339 
  3362 
  3340 	for(;p->mode==0;p++) {
  3363 	for(;p->mode==0;p++) {
  3341 		tile2 = TILE_ADD(tile, p->tileoffs);
  3364 		tile2 = TILE_ADD(tile, p->tileoffs);
  3342 		w = _airport_size_x[p->attr];
  3365 		w = _airport_size_x[p->attr];
  3343 		h = _airport_size_y[p->attr];
  3366 		h = _airport_size_y[p->attr];
  3344 		if (cargo & 0x80) {
  3367 		if (cargo & 0x80) {
  3345 			GetProductionAroundTiles(values, tile2, w, h);
  3368 			GetProductionAroundTiles(values, tile2, w, h, rad);
  3346 			return values[cargo & 0x7F] != 0;
  3369 			return values[cargo & 0x7F] != 0;
  3347 		} else {
  3370 		} else {
  3348 			GetAcceptanceAroundTiles(values, tile2, w, h);
  3371 			GetAcceptanceAroundTiles(values, tile2, w, h, rad);
  3349 			return values[cargo] >= 8;
  3372 			return values[cargo] >= 8;
  3350 		}
  3373 		}
  3351 	}
  3374 	}
  3352 	return true;
  3375 	return true;
  3353 }
  3376 }