src/disaster_cmd.cpp
branchgamebalance
changeset 9895 7bd07f43b0e3
parent 6479 b228a94a1832
child 9907 3b068c3a1c74
equal deleted inserted replaced
9894:70d78ac95d6c 9895:7bd07f43b0e3
   114 	if (img == 0) img = _disaster_images[v->subtype][v->direction];
   114 	if (img == 0) img = _disaster_images[v->subtype][v->direction];
   115 	v->cur_image = img;
   115 	v->cur_image = img;
   116 }
   116 }
   117 
   117 
   118 
   118 
   119 /** Initialize a disaster vehicle. These vehicles are of type VEH_Disaster, are unclickable
   119 /** Initialize a disaster vehicle. These vehicles are of type VEH_DISASTER, are unclickable
   120  * and owned by nobody */
   120  * and owned by nobody */
   121 static void InitializeDisasterVehicle(Vehicle *v, int x, int y, byte z, Direction direction, byte subtype)
   121 static void InitializeDisasterVehicle(Vehicle *v, int x, int y, byte z, Direction direction, byte subtype)
   122 {
   122 {
   123 	v->type = VEH_Disaster;
   123 	v->type = VEH_DISASTER;
   124 	v->x_pos = x;
   124 	v->x_pos = x;
   125 	v->y_pos = y;
   125 	v->y_pos = y;
   126 	v->z_pos = z;
   126 	v->z_pos = z;
   127 	v->tile = TileVirtXY(x, y);
   127 	v->tile = TileVirtXY(x, y);
   128 	v->direction = direction;
   128 	v->direction = direction;
   133 	v->sprite_height = 2;
   133 	v->sprite_height = 2;
   134 	v->z_height = 5;
   134 	v->z_height = 5;
   135 	v->owner = OWNER_NONE;
   135 	v->owner = OWNER_NONE;
   136 	v->vehstatus = VS_UNCLICKABLE;
   136 	v->vehstatus = VS_UNCLICKABLE;
   137 	v->u.disaster.image_override = 0;
   137 	v->u.disaster.image_override = 0;
   138 	v->current_order.type = OT_NOTHING;
   138 	v->current_order.Free();
   139 	v->current_order.flags = 0;
       
   140 	v->current_order.dest = 0;
       
   141 
   139 
   142 	DisasterVehicleUpdateImage(v);
   140 	DisasterVehicleUpdateImage(v);
   143 	VehiclePositionChanged(v);
   141 	VehiclePositionChanged(v);
   144 	BeginVehicleMove(v);
   142 	BeginVehicleMove(v);
   145 	EndVehicleMove(v);
   143 	EndVehicleMove(v);
   328 			return;
   326 			return;
   329 		}
   327 		}
   330 		v->current_order.dest = 1;
   328 		v->current_order.dest = 1;
   331 
   329 
   332 		FOR_ALL_VEHICLES(u) {
   330 		FOR_ALL_VEHICLES(u) {
   333 			if (u->type == VEH_Road && IsHumanPlayer(u->owner)) {
   331 			if (u->type == VEH_ROAD && IsHumanPlayer(u->owner)) {
   334 				v->dest_tile = u->index;
   332 				v->dest_tile = u->index;
   335 				v->age = 0;
   333 				v->age = 0;
   336 				return;
   334 				return;
   337 			}
   335 			}
   338 		}
   336 		}
   339 
   337 
   340 		DeleteDisasterVeh(v);
   338 		DeleteDisasterVeh(v);
   341 	} else {
   339 	} else {
   342 		/* Target a vehicle */
   340 		/* Target a vehicle */
   343 		u = GetVehicle(v->dest_tile);
   341 		u = GetVehicle(v->dest_tile);
   344 		if (u->type != VEH_Road) {
   342 		if (u->type != VEH_ROAD) {
   345 			DeleteDisasterVeh(v);
   343 			DeleteDisasterVeh(v);
   346 			return;
   344 			return;
   347 		}
   345 		}
   348 
   346 
   349 		dist = delta(v->x_pos, u->x_pos) + delta(v->y_pos, u->y_pos);
   347 		dist = delta(v->x_pos, u->x_pos) + delta(v->y_pos, u->y_pos);
   588 		}
   586 		}
   589 
   587 
   590 		v->current_order.dest = 2;
   588 		v->current_order.dest = 2;
   591 
   589 
   592 		FOR_ALL_VEHICLES(u) {
   590 		FOR_ALL_VEHICLES(u) {
   593 			if (u->type == VEH_Train || u->type == VEH_Road) {
   591 			if (u->type == VEH_TRAIN || u->type == VEH_ROAD) {
   594 				if (delta(u->x_pos, v->x_pos) + delta(u->y_pos, v->y_pos) <= 12 * TILE_SIZE) {
   592 				if (delta(u->x_pos, v->x_pos) + delta(u->y_pos, v->y_pos) <= 12 * TILE_SIZE) {
   595 					u->breakdown_ctr = 5;
   593 					u->breakdown_ctr = 5;
   596 					u->breakdown_delay = 0xF0;
   594 					u->breakdown_delay = 0xF0;
   597 				}
   595 				}
   598 			}
   596 			}
   756 void OnNewDay_DisasterVehicle(Vehicle *v)
   754 void OnNewDay_DisasterVehicle(Vehicle *v)
   757 {
   755 {
   758 	// not used
   756 	// not used
   759 }
   757 }
   760 
   758 
   761 typedef void DisasterInitProc(void);
   759 typedef void DisasterInitProc();
   762 
   760 
   763 
   761 
   764 /** Zeppeliner which crashes on a small airport if one found,
   762 /** Zeppeliner which crashes on a small airport if one found,
   765  * otherwise crashes on a random tile */
   763  * otherwise crashes on a random tile */
   766 static void Disaster_Zeppeliner_Init(void)
   764 static void Disaster_Zeppeliner_Init()
   767 {
   765 {
   768 	Vehicle *v = ForceAllocateSpecialVehicle(), *u;
   766 	Vehicle *v = ForceAllocateSpecialVehicle(), *u;
   769 	Station *st;
   767 	Station *st;
   770 	int x;
   768 	int x;
   771 
   769 
   795 }
   793 }
   796 
   794 
   797 
   795 
   798 /** Ufo which flies around aimlessly from the middle of the map a bit
   796 /** Ufo which flies around aimlessly from the middle of the map a bit
   799  * until it locates a road vehicle which it targets and then destroys */
   797  * until it locates a road vehicle which it targets and then destroys */
   800 static void Disaster_Small_Ufo_Init(void)
   798 static void Disaster_Small_Ufo_Init()
   801 {
   799 {
   802 	Vehicle *v = ForceAllocateSpecialVehicle(), *u;
   800 	Vehicle *v = ForceAllocateSpecialVehicle(), *u;
   803 	int x;
   801 	int x;
   804 
   802 
   805 	if (v == NULL) return;
   803 	if (v == NULL) return;
   819 	}
   817 	}
   820 }
   818 }
   821 
   819 
   822 
   820 
   823 /* Combat airplane which destroys an oil refinery */
   821 /* Combat airplane which destroys an oil refinery */
   824 static void Disaster_Airplane_Init(void)
   822 static void Disaster_Airplane_Init()
   825 {
   823 {
   826 	Industry *i, *found;
   824 	Industry *i, *found;
   827 	Vehicle *v, *u;
   825 	Vehicle *v, *u;
   828 	int x, y;
   826 	int x, y;
   829 
   827 
   855 	}
   853 	}
   856 }
   854 }
   857 
   855 
   858 
   856 
   859 /** Combat helicopter that destroys a factory */
   857 /** Combat helicopter that destroys a factory */
   860 static void Disaster_Helicopter_Init(void)
   858 static void Disaster_Helicopter_Init()
   861 {
   859 {
   862 	Industry *i, *found;
   860 	Industry *i, *found;
   863 	Vehicle *v, *u, *w;
   861 	Vehicle *v, *u, *w;
   864 	int x, y;
   862 	int x, y;
   865 
   863 
   897 }
   895 }
   898 
   896 
   899 
   897 
   900 /* Big Ufo which lands on a piece of rail and will consequently be shot
   898 /* Big Ufo which lands on a piece of rail and will consequently be shot
   901  * down by a combat airplane, destroying the surroundings */
   899  * down by a combat airplane, destroying the surroundings */
   902 static void Disaster_Big_Ufo_Init(void)
   900 static void Disaster_Big_Ufo_Init()
   903 {
   901 {
   904 	Vehicle *v = ForceAllocateSpecialVehicle(), *u;
   902 	Vehicle *v = ForceAllocateSpecialVehicle(), *u;
   905 	int x, y;
   903 	int x, y;
   906 
   904 
   907 	if (v == NULL) return;
   905 	if (v == NULL) return;
   922 	}
   920 	}
   923 }
   921 }
   924 
   922 
   925 
   923 
   926 /* Curious submarine #1, just floats around */
   924 /* Curious submarine #1, just floats around */
   927 static void Disaster_Small_Submarine_Init(void)
   925 static void Disaster_Small_Submarine_Init()
   928 {
   926 {
   929 	Vehicle *v = ForceAllocateSpecialVehicle();
   927 	Vehicle *v = ForceAllocateSpecialVehicle();
   930 	int x, y;
   928 	int x, y;
   931 	Direction dir;
   929 	Direction dir;
   932 	uint32 r;
   930 	uint32 r;
   947 	v->age = 0;
   945 	v->age = 0;
   948 }
   946 }
   949 
   947 
   950 
   948 
   951 /* Curious submarine #2, just floats around */
   949 /* Curious submarine #2, just floats around */
   952 static void Disaster_Big_Submarine_Init(void)
   950 static void Disaster_Big_Submarine_Init()
   953 {
   951 {
   954 	Vehicle *v = ForceAllocateSpecialVehicle();
   952 	Vehicle *v = ForceAllocateSpecialVehicle();
   955 	int x,y;
   953 	int x,y;
   956 	Direction dir;
   954 	Direction dir;
   957 	uint32 r;
   955 	uint32 r;
   973 }
   971 }
   974 
   972 
   975 
   973 
   976 /** Coal mine catastrophe, destroys a stretch of 30 tiles of
   974 /** Coal mine catastrophe, destroys a stretch of 30 tiles of
   977  * land in a certain direction */
   975  * land in a certain direction */
   978 static void Disaster_CoalMine_Init(void)
   976 static void Disaster_CoalMine_Init()
   979 {
   977 {
   980 	int index = GB(Random(), 0, 4);
   978 	int index = GB(Random(), 0, 4);
   981 	uint m;
   979 	uint m;
   982 
   980 
   983 	for (m = 0; m < 15; m++) {
   981 	for (m = 0; m < 15; m++) {
  1029 	{ 1975, 2010 }, ///< submarine (big)
  1027 	{ 1975, 2010 }, ///< submarine (big)
  1030 	{ 1950, 1985 }  ///< coalmine
  1028 	{ 1950, 1985 }  ///< coalmine
  1031 };
  1029 };
  1032 
  1030 
  1033 
  1031 
  1034 static void DoDisaster(void)
  1032 static void DoDisaster()
  1035 {
  1033 {
  1036 	byte buf[lengthof(_dis_years)];
  1034 	byte buf[lengthof(_dis_years)];
  1037 	uint i;
  1035 	uint i;
  1038 	uint j;
  1036 	uint j;
  1039 
  1037 
  1046 
  1044 
  1047 	_disaster_initprocs[buf[RandomRange(j)]]();
  1045 	_disaster_initprocs[buf[RandomRange(j)]]();
  1048 }
  1046 }
  1049 
  1047 
  1050 
  1048 
  1051 static void ResetDisasterDelay(void)
  1049 static void ResetDisasterDelay()
  1052 {
  1050 {
  1053 	_disaster_delay = GB(Random(), 0, 9) + 730;
  1051 	_disaster_delay = GB(Random(), 0, 9) + 730;
  1054 }
  1052 }
  1055 
  1053 
  1056 void DisasterDailyLoop(void)
  1054 void DisasterDailyLoop()
  1057 {
  1055 {
  1058 	if (--_disaster_delay != 0) return;
  1056 	if (--_disaster_delay != 0) return;
  1059 
  1057 
  1060 	ResetDisasterDelay();
  1058 	ResetDisasterDelay();
  1061 
  1059 
  1062 	if (_opt.diff.disasters != 0) DoDisaster();
  1060 	if (_opt.diff.disasters != 0) DoDisaster();
  1063 }
  1061 }
  1064 
  1062 
  1065 void StartupDisasters(void)
  1063 void StartupDisasters()
  1066 {
  1064 {
  1067 	ResetDisasterDelay();
  1065 	ResetDisasterDelay();
  1068 }
  1066 }