water_cmd.c
changeset 149 5f7d4b21df01
parent 43 3b93861c5478
child 159 139cf78bfb28
equal deleted inserted replaced
148:6a72b12f5588 149:5f7d4b21df01
     2 #include "ttd.h"
     2 #include "ttd.h"
     3 #include "vehicle.h"
     3 #include "vehicle.h"
     4 #include "viewport.h"
     4 #include "viewport.h"
     5 #include "command.h"
     5 #include "command.h"
     6 #include "town.h"
     6 #include "town.h"
       
     7 #include "news.h"
       
     8 
       
     9 static void FloodVehicle(Vehicle *v);
     7 
    10 
     8 bool IsShipDepotTile(TileIndex tile)
    11 bool IsShipDepotTile(TileIndex tile)
     9 {
    12 {
    10 	return IS_TILETYPE(tile, MP_WATER) &&	(_map5[tile]&~3) == 0x80;
    13 	return IS_TILETYPE(tile, MP_WATER) &&	(_map5[tile]&~3) == 0x80;
    11 }
    14 }
   504 				return;
   507 				return;
   505 			}
   508 			}
   506 		}
   509 		}
   507 
   510 
   508 		_current_player = OWNER_WATER;
   511 		_current_player = OWNER_WATER;
       
   512 		{
       
   513 			Vehicle *v = FindVehicleBetween(tile, tile, 0);
       
   514 			if (v != NULL) {FloodVehicle(v);}
       
   515 		}
   509 		if (DoCommandByTile(tile,0,0,DC_EXEC, CMD_LANDSCAPE_CLEAR) != CMD_ERROR)
   516 		if (DoCommandByTile(tile,0,0,DC_EXEC, CMD_LANDSCAPE_CLEAR) != CMD_ERROR)
   510 			ModifyTile(tile, MP_SETTYPE(MP_WATER) | MP_MAPOWNER | MP_MAP5 | MP_MAP2_CLEAR | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR,OWNER_WATER,0);
   517 			ModifyTile(tile, MP_SETTYPE(MP_WATER) | MP_MAPOWNER | MP_MAP5 | MP_MAP2_CLEAR | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR,OWNER_WATER,0);
   511 	}
   518 	}
       
   519 }
       
   520 
       
   521 static void FloodVehicle(Vehicle *v)
       
   522 {
       
   523 	Vehicle *u;
       
   524 	uint16 pass;
       
   525 	if (!(v->vehstatus & VS_CRASHED)) {
       
   526 
       
   527 		if (v->type == VEH_Road) {	// flood bus/truck
       
   528 			pass = 1;	// driver
       
   529 			if (v->cargo_type == CT_PASSENGERS)
       
   530 				pass += v->cargo_count;
       
   531 
       
   532 			v->vehstatus |= VS_CRASHED;
       
   533 			v->u.road.crashed_ctr = 2000;	// max 2220, disappear pretty fast
       
   534 			InvalidateWindow(WC_ROADVEH_LIST, v->owner);
       
   535 		}
       
   536 		
       
   537 		else if (v->type == VEH_Train) {
       
   538 			v = GetFirstVehicleInChain(v);
       
   539 			u = v;
       
   540 			pass = 4;	// driver
       
   541 
       
   542 			// crash all wagons, and count passangers
       
   543 			BEGIN_ENUM_WAGONS(v)
       
   544 				if (v->cargo_type == CT_PASSENGERS) pass += v->cargo_count;
       
   545 				v->vehstatus |= VS_CRASHED;
       
   546 			END_ENUM_WAGONS(v)
       
   547 
       
   548 			v = u;
       
   549 			v->u.rail.crash_anim_pos = 4000; // max 4440, disappear pretty fast
       
   550 			InvalidateWindow(WC_TRAINS_LIST, v->owner);						
       
   551 		}
       
   552 
       
   553 		InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, 4);
       
   554 		InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
       
   555 		
       
   556 		SET_DPARAM16(0, pass);
       
   557 		AddNewsItem(STR_B006_FLOOD_VEHICLE_DESTROYED,
       
   558 			NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_VEHICLE, NT_ACCIDENT, 0),
       
   559 			v->index,
       
   560 			0);
       
   561 	}
       
   562 	CreateEffectVehicleRel(v,4,4,8,EV_CRASHED_SMOKE);	// show cool destruction effects
       
   563 	SndPlayVehicleFx(16, v); // create sound
   512 }
   564 }
   513 
   565 
   514 // called from tunnelbridge_cmd
   566 // called from tunnelbridge_cmd
   515 void TileLoop_Water(uint tile)
   567 void TileLoop_Water(uint tile)
   516 {
   568 {