src/disaster_cmd.cpp
changeset 6573 7624f942237f
parent 6479 b228a94a1832
child 6585 7da94b26498a
equal deleted inserted replaced
6572:e35266003390 6573:7624f942237f
   756 void OnNewDay_DisasterVehicle(Vehicle *v)
   756 void OnNewDay_DisasterVehicle(Vehicle *v)
   757 {
   757 {
   758 	// not used
   758 	// not used
   759 }
   759 }
   760 
   760 
   761 typedef void DisasterInitProc(void);
   761 typedef void DisasterInitProc();
   762 
   762 
   763 
   763 
   764 /** Zeppeliner which crashes on a small airport if one found,
   764 /** Zeppeliner which crashes on a small airport if one found,
   765  * otherwise crashes on a random tile */
   765  * otherwise crashes on a random tile */
   766 static void Disaster_Zeppeliner_Init(void)
   766 static void Disaster_Zeppeliner_Init()
   767 {
   767 {
   768 	Vehicle *v = ForceAllocateSpecialVehicle(), *u;
   768 	Vehicle *v = ForceAllocateSpecialVehicle(), *u;
   769 	Station *st;
   769 	Station *st;
   770 	int x;
   770 	int x;
   771 
   771 
   795 }
   795 }
   796 
   796 
   797 
   797 
   798 /** Ufo which flies around aimlessly from the middle of the map a bit
   798 /** 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 */
   799  * until it locates a road vehicle which it targets and then destroys */
   800 static void Disaster_Small_Ufo_Init(void)
   800 static void Disaster_Small_Ufo_Init()
   801 {
   801 {
   802 	Vehicle *v = ForceAllocateSpecialVehicle(), *u;
   802 	Vehicle *v = ForceAllocateSpecialVehicle(), *u;
   803 	int x;
   803 	int x;
   804 
   804 
   805 	if (v == NULL) return;
   805 	if (v == NULL) return;
   819 	}
   819 	}
   820 }
   820 }
   821 
   821 
   822 
   822 
   823 /* Combat airplane which destroys an oil refinery */
   823 /* Combat airplane which destroys an oil refinery */
   824 static void Disaster_Airplane_Init(void)
   824 static void Disaster_Airplane_Init()
   825 {
   825 {
   826 	Industry *i, *found;
   826 	Industry *i, *found;
   827 	Vehicle *v, *u;
   827 	Vehicle *v, *u;
   828 	int x, y;
   828 	int x, y;
   829 
   829 
   855 	}
   855 	}
   856 }
   856 }
   857 
   857 
   858 
   858 
   859 /** Combat helicopter that destroys a factory */
   859 /** Combat helicopter that destroys a factory */
   860 static void Disaster_Helicopter_Init(void)
   860 static void Disaster_Helicopter_Init()
   861 {
   861 {
   862 	Industry *i, *found;
   862 	Industry *i, *found;
   863 	Vehicle *v, *u, *w;
   863 	Vehicle *v, *u, *w;
   864 	int x, y;
   864 	int x, y;
   865 
   865 
   897 }
   897 }
   898 
   898 
   899 
   899 
   900 /* Big Ufo which lands on a piece of rail and will consequently be shot
   900 /* Big Ufo which lands on a piece of rail and will consequently be shot
   901  * down by a combat airplane, destroying the surroundings */
   901  * down by a combat airplane, destroying the surroundings */
   902 static void Disaster_Big_Ufo_Init(void)
   902 static void Disaster_Big_Ufo_Init()
   903 {
   903 {
   904 	Vehicle *v = ForceAllocateSpecialVehicle(), *u;
   904 	Vehicle *v = ForceAllocateSpecialVehicle(), *u;
   905 	int x, y;
   905 	int x, y;
   906 
   906 
   907 	if (v == NULL) return;
   907 	if (v == NULL) return;
   922 	}
   922 	}
   923 }
   923 }
   924 
   924 
   925 
   925 
   926 /* Curious submarine #1, just floats around */
   926 /* Curious submarine #1, just floats around */
   927 static void Disaster_Small_Submarine_Init(void)
   927 static void Disaster_Small_Submarine_Init()
   928 {
   928 {
   929 	Vehicle *v = ForceAllocateSpecialVehicle();
   929 	Vehicle *v = ForceAllocateSpecialVehicle();
   930 	int x, y;
   930 	int x, y;
   931 	Direction dir;
   931 	Direction dir;
   932 	uint32 r;
   932 	uint32 r;
   947 	v->age = 0;
   947 	v->age = 0;
   948 }
   948 }
   949 
   949 
   950 
   950 
   951 /* Curious submarine #2, just floats around */
   951 /* Curious submarine #2, just floats around */
   952 static void Disaster_Big_Submarine_Init(void)
   952 static void Disaster_Big_Submarine_Init()
   953 {
   953 {
   954 	Vehicle *v = ForceAllocateSpecialVehicle();
   954 	Vehicle *v = ForceAllocateSpecialVehicle();
   955 	int x,y;
   955 	int x,y;
   956 	Direction dir;
   956 	Direction dir;
   957 	uint32 r;
   957 	uint32 r;
   973 }
   973 }
   974 
   974 
   975 
   975 
   976 /** Coal mine catastrophe, destroys a stretch of 30 tiles of
   976 /** Coal mine catastrophe, destroys a stretch of 30 tiles of
   977  * land in a certain direction */
   977  * land in a certain direction */
   978 static void Disaster_CoalMine_Init(void)
   978 static void Disaster_CoalMine_Init()
   979 {
   979 {
   980 	int index = GB(Random(), 0, 4);
   980 	int index = GB(Random(), 0, 4);
   981 	uint m;
   981 	uint m;
   982 
   982 
   983 	for (m = 0; m < 15; m++) {
   983 	for (m = 0; m < 15; m++) {
  1029 	{ 1975, 2010 }, ///< submarine (big)
  1029 	{ 1975, 2010 }, ///< submarine (big)
  1030 	{ 1950, 1985 }  ///< coalmine
  1030 	{ 1950, 1985 }  ///< coalmine
  1031 };
  1031 };
  1032 
  1032 
  1033 
  1033 
  1034 static void DoDisaster(void)
  1034 static void DoDisaster()
  1035 {
  1035 {
  1036 	byte buf[lengthof(_dis_years)];
  1036 	byte buf[lengthof(_dis_years)];
  1037 	uint i;
  1037 	uint i;
  1038 	uint j;
  1038 	uint j;
  1039 
  1039 
  1046 
  1046 
  1047 	_disaster_initprocs[buf[RandomRange(j)]]();
  1047 	_disaster_initprocs[buf[RandomRange(j)]]();
  1048 }
  1048 }
  1049 
  1049 
  1050 
  1050 
  1051 static void ResetDisasterDelay(void)
  1051 static void ResetDisasterDelay()
  1052 {
  1052 {
  1053 	_disaster_delay = GB(Random(), 0, 9) + 730;
  1053 	_disaster_delay = GB(Random(), 0, 9) + 730;
  1054 }
  1054 }
  1055 
  1055 
  1056 void DisasterDailyLoop(void)
  1056 void DisasterDailyLoop()
  1057 {
  1057 {
  1058 	if (--_disaster_delay != 0) return;
  1058 	if (--_disaster_delay != 0) return;
  1059 
  1059 
  1060 	ResetDisasterDelay();
  1060 	ResetDisasterDelay();
  1061 
  1061 
  1062 	if (_opt.diff.disasters != 0) DoDisaster();
  1062 	if (_opt.diff.disasters != 0) DoDisaster();
  1063 }
  1063 }
  1064 
  1064 
  1065 void StartupDisasters(void)
  1065 void StartupDisasters()
  1066 {
  1066 {
  1067 	ResetDisasterDelay();
  1067 	ResetDisasterDelay();
  1068 }
  1068 }