ai/default/default.c
changeset 4434 4175805666a5
parent 4389 e4555522d257
child 4495 b44566fc9025
equal deleted inserted replaced
4433:2ee8e92ef389 4434:4175805666a5
  2417 		if (++p->ai.state_counter == 1000) {
  2417 		if (++p->ai.state_counter == 1000) {
  2418 			for (i = 0; p->ai.wagon_list[i] != INVALID_VEHICLE; i++) {
  2418 			for (i = 0; p->ai.wagon_list[i] != INVALID_VEHICLE; i++) {
  2419 				cost = DoCommand(tile, p->ai.wagon_list[i], 0, DC_EXEC, CMD_SELL_RAIL_WAGON);
  2419 				cost = DoCommand(tile, p->ai.wagon_list[i], 0, DC_EXEC, CMD_SELL_RAIL_WAGON);
  2420 				assert(!CmdFailed(cost));
  2420 				assert(!CmdFailed(cost));
  2421 			}
  2421 			}
  2422 			p->ai.state =	AIS_0;
  2422 			p->ai.state = AIS_0;
  2423 		}
  2423 		}
  2424 		return;
  2424 		return;
  2425 	}
  2425 	}
  2426 
  2426 
  2427 	// Try to build the locomotive
  2427 	// Try to build the locomotive
  2457 
  2457 
  2458 		if (!is_pass && i == 1) order.flags |= OF_UNLOAD;
  2458 		if (!is_pass && i == 1) order.flags |= OF_UNLOAD;
  2459 		if (p->ai.num_want_fullload != 0 && (is_pass || i == 0))
  2459 		if (p->ai.num_want_fullload != 0 && (is_pass || i == 0))
  2460 			order.flags |= OF_FULL_LOAD;
  2460 			order.flags |= OF_FULL_LOAD;
  2461 
  2461 
  2462 		DoCommand(0, loco_id + (i << 16),	PackOrder(&order), DC_EXEC, CMD_INSERT_ORDER);
  2462 		DoCommand(0, loco_id + (i << 16), PackOrder(&order), DC_EXEC, CMD_INSERT_ORDER);
  2463 	}
  2463 	}
  2464 
  2464 
  2465 	DoCommand(0, loco_id, 0, DC_EXEC, CMD_START_STOP_TRAIN);
  2465 	DoCommand(0, loco_id, 0, DC_EXEC, CMD_START_STOP_TRAIN);
  2466 
  2466 
  2467 	DoCommand(0, loco_id, _ai_service_interval, DC_EXEC, CMD_CHANGE_SERVICE_INT);
  2467 	DoCommand(0, loco_id, _ai_service_interval, DC_EXEC, CMD_CHANGE_SERVICE_INT);
  2470 
  2470 
  2471 	if (--p->ai.num_loco_to_build != 0) {
  2471 	if (--p->ai.num_loco_to_build != 0) {
  2472 //		p->ai.loco_id = INVALID_VEHICLE;
  2472 //		p->ai.loco_id = INVALID_VEHICLE;
  2473 		p->ai.wagon_list[0] = INVALID_VEHICLE;
  2473 		p->ai.wagon_list[0] = INVALID_VEHICLE;
  2474 	} else {
  2474 	} else {
  2475 		p->ai.state =	AIS_0;
  2475 		p->ai.state = AIS_0;
  2476 	}
  2476 	}
  2477 }
  2477 }
  2478 
  2478 
  2479 static void AiStateDeleteRailBlocks(Player *p)
  2479 static void AiStateDeleteRailBlocks(Player *p)
  2480 {
  2480 {
  2497 {
  2497 {
  2498 	uint values[NUM_CARGO];
  2498 	uint values[NUM_CARGO];
  2499 	int rad;
  2499 	int rad;
  2500 
  2500 
  2501 	if (_patches.modified_catchment) {
  2501 	if (_patches.modified_catchment) {
  2502 		rad = CA_TRUCK;		//Same as CA_BUS at the moment?
  2502 		rad = CA_TRUCK; // Same as CA_BUS at the moment?
  2503 	} else {			//change that at some point?
  2503 	} else { // change that at some point?
  2504 		rad = 4;
  2504 		rad = 4;
  2505 	}
  2505 	}
  2506 
  2506 
  2507 	for (;; p++) {
  2507 	for (;; p++) {
  2508 		if (p->mode == 4) {
  2508 		if (p->mode == 4) {
  3008 		int i;
  3008 		int i;
  3009 		int32 bridge_len;
  3009 		int32 bridge_len;
  3010 		p->ai.cur_tile_a = arf.bridge_end_tile;
  3010 		p->ai.cur_tile_a = arf.bridge_end_tile;
  3011 		bridge_len = GetBridgeLength(tile, p->ai.cur_tile_a); // tile
  3011 		bridge_len = GetBridgeLength(tile, p->ai.cur_tile_a); // tile
  3012 
  3012 
  3013 		/*	Figure out what (road)bridge type to build
  3013 		/* Figure out what (road)bridge type to build
  3014 				start with best bridge, then go down to worse and worse bridges
  3014 		 * start with best bridge, then go down to worse and worse bridges
  3015 				unnecessary to check for worse bridge (i=0), since AI will always build that.
  3015 		 * unnecessary to check for worse bridge (i=0), since AI will always build that.
  3016 				AI is so fucked up that fixing this small thing will probably not solve a thing
  3016 		 *AI is so fucked up that fixing this small thing will probably not solve a thing
  3017 		*/
  3017 		 */
  3018 		for (i = 10; i != 0; i--) {
  3018 		for (i = 10; i != 0; i--) {
  3019 			if (CheckBridge_Stuff(i, bridge_len)) {
  3019 			if (CheckBridge_Stuff(i, bridge_len)) {
  3020 				int32 cost = DoCommand(tile, p->ai.cur_tile_a, i + (0x80 << 8), DC_AUTO, CMD_BUILD_BRIDGE);
  3020 				int32 cost = DoCommand(tile, p->ai.cur_tile_a, i + (0x80 << 8), DC_AUTO, CMD_BUILD_BRIDGE);
  3021 				if (!CmdFailed(cost) && cost < (p->player_money >> 5)) break;
  3021 				if (!CmdFailed(cost) && cost < (p->player_money >> 5)) break;
  3022 			}
  3022 			}
  3189 
  3189 
  3190 		if (!is_pass && i == 1) order.flags |= OF_UNLOAD;
  3190 		if (!is_pass && i == 1) order.flags |= OF_UNLOAD;
  3191 		if (p->ai.num_want_fullload != 0 && (is_pass || i == 0))
  3191 		if (p->ai.num_want_fullload != 0 && (is_pass || i == 0))
  3192 			order.flags |= OF_FULL_LOAD;
  3192 			order.flags |= OF_FULL_LOAD;
  3193 
  3193 
  3194 		DoCommand(0, loco_id + (i << 16),	PackOrder(&order), DC_EXEC, CMD_INSERT_ORDER);
  3194 		DoCommand(0, loco_id + (i << 16), PackOrder(&order), DC_EXEC, CMD_INSERT_ORDER);
  3195 	}
  3195 	}
  3196 
  3196 
  3197 	DoCommand(0, loco_id, 0, DC_EXEC, CMD_START_STOP_ROADVEH);
  3197 	DoCommand(0, loco_id, 0, DC_EXEC, CMD_START_STOP_ROADVEH);
  3198 	DoCommand(0, loco_id, _ai_service_interval, DC_EXEC, CMD_CHANGE_SERVICE_INT);
  3198 	DoCommand(0, loco_id, _ai_service_interval, DC_EXEC, CMD_CHANGE_SERVICE_INT);
  3199 
  3199 
  3318 {
  3318 {
  3319 	uint values[NUM_CARGO];
  3319 	uint values[NUM_CARGO];
  3320 	int rad;
  3320 	int rad;
  3321 
  3321 
  3322 	if (_patches.modified_catchment) {
  3322 	if (_patches.modified_catchment) {
  3323 		rad = CA_AIR_LARGE;		//I Have NFI what airport the
  3323 		rad = CA_AIR_LARGE; // I Have NFI what airport the
  3324 	} else {				//AI is going to build here
  3324 	} else { // AI is going to build here
  3325 		rad = 4;
  3325 		rad = 4;
  3326 	}
  3326 	}
  3327 
  3327 
  3328 	for (; p->mode == 0; p++) {
  3328 	for (; p->mode == 0; p++) {
  3329 		TileIndex tile2 = TILE_ADD(tile, ToTileIndexDiff(p->tileoffs));
  3329 		TileIndex tile2 = TILE_ADD(tile, ToTileIndexDiff(p->tileoffs));