disaster_cmd.c
changeset 926 a6d140a6a4de
parent 919 544f374ee392
child 1035 812f837ee03f
equal deleted inserted replaced
925:47d7952c6c14 926:a6d140a6a4de
   251 
   251 
   252 	v->u.disaster.image_override = (++v->tick_counter & 8) ? 0xF45 : 0xF44;
   252 	v->u.disaster.image_override = (++v->tick_counter & 8) ? 0xF45 : 0xF44;
   253 
   253 
   254 	if (v->current_order.station == 0) {
   254 	if (v->current_order.station == 0) {
   255 // fly around randomly
   255 // fly around randomly
   256 		int x = GET_TILE_X(v->dest_tile)*16;
   256 		int x = TileX(v->dest_tile) * 16;
   257 		int y = GET_TILE_Y(v->dest_tile)*16;
   257 		int y = TileY(v->dest_tile) * 16;
   258 		if (abs(x - v->x_pos) +	abs(y - v->y_pos) >= 16) {
   258 		if (abs(x - v->x_pos) +	abs(y - v->y_pos) >= 16) {
   259 			v->direction = GetDirectionTowards(v, x, y);
   259 			v->direction = GetDirectionTowards(v, x, y);
   260 			GetNewVehiclePos(v, &gp);
   260 			GetNewVehiclePos(v, &gp);
   261 			SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos);
   261 			SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos);
   262 			return;
   262 			return;
   350 	}
   350 	}
   351 
   351 
   352 	if (v->current_order.station == 2) {
   352 	if (v->current_order.station == 2) {
   353 		if (!(v->tick_counter&3)) {
   353 		if (!(v->tick_counter&3)) {
   354 			Industry *i = GetIndustry(v->dest_tile);
   354 			Industry *i = GetIndustry(v->dest_tile);
   355 			int x = GET_TILE_X(i->xy)*16;
   355 			int x = TileX(i->xy) * 16;
   356 			int y = GET_TILE_Y(i->xy)*16;
   356 			int y = TileY(i->xy) * 16;
   357 			uint32 r = Random();
   357 			uint32 r = Random();
   358 
   358 
   359 			CreateEffectVehicleAbove(
   359 			CreateEffectVehicleAbove(
   360 				x + (r & 0x3F),
   360 				x + (r & 0x3F),
   361 				y + (r >> 6 & 0x3F),
   361 				y + (r >> 6 & 0x3F),
   421 	}
   421 	}
   422 
   422 
   423 	if (v->current_order.station == 2) {
   423 	if (v->current_order.station == 2) {
   424 		if (!(v->tick_counter&3)) {
   424 		if (!(v->tick_counter&3)) {
   425 			Industry *i = GetIndustry(v->dest_tile);
   425 			Industry *i = GetIndustry(v->dest_tile);
   426 			int x = GET_TILE_X(i->xy)*16;
   426 			int x = TileX(i->xy) * 16;
   427 			int y = GET_TILE_Y(i->xy)*16;
   427 			int y = TileY(i->xy) * 16;
   428 			uint32 r = Random();
   428 			uint32 r = Random();
   429 
   429 
   430 			CreateEffectVehicleAbove(
   430 			CreateEffectVehicleAbove(
   431 				x + (r & 0x3F),
   431 				x + (r & 0x3F),
   432 				y + (r >> 6 & 0x3F),
   432 				y + (r >> 6 & 0x3F),
   499 	uint tile,tile_org;
   499 	uint tile,tile_org;
   500 
   500 
   501 	v->tick_counter++;
   501 	v->tick_counter++;
   502 
   502 
   503 	if (v->current_order.station == 1) {
   503 	if (v->current_order.station == 1) {
   504 		int x = GET_TILE_X(v->dest_tile)*16 + 8;
   504 		int x = TileX(v->dest_tile) * 16 + 8;
   505 		int y = GET_TILE_Y(v->dest_tile)*16 + 8;
   505 		int y = TileY(v->dest_tile) * 16 + 8;
   506 		if (abs(v->x_pos - x) + abs(v->y_pos - y) >= 8) {
   506 		if (abs(v->x_pos - x) + abs(v->y_pos - y) >= 8) {
   507 			v->direction = GetDirectionTowards(v, x, y);
   507 			v->direction = GetDirectionTowards(v, x, y);
   508 
   508 
   509 			GetNewVehiclePos(v, &gp);
   509 			GetNewVehiclePos(v, &gp);
   510 			SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos);
   510 			SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos);
   551 		u->next = w;
   551 		u->next = w;
   552 		InitializeDisasterVehicle(w, -6*16, v->y_pos, 0, 5, 12);
   552 		InitializeDisasterVehicle(w, -6*16, v->y_pos, 0, 5, 12);
   553 		w->vehstatus |= VS_DISASTER;
   553 		w->vehstatus |= VS_DISASTER;
   554 	} else if (v->current_order.station < 1) {
   554 	} else if (v->current_order.station < 1) {
   555 
   555 
   556 		int x = GET_TILE_X(v->dest_tile)*16;
   556 		int x = TileX(v->dest_tile) * 16;
   557 		int y = GET_TILE_Y(v->dest_tile)*16;
   557 		int y = TileY(v->dest_tile) * 16;
   558 		if (abs(x - v->x_pos) +	abs(y - v->y_pos) >= 16) {
   558 		if (abs(x - v->x_pos) +	abs(y - v->y_pos) >= 16) {
   559 			v->direction = GetDirectionTowards(v, x, y);
   559 			v->direction = GetDirectionTowards(v, x, y);
   560 			GetNewVehiclePos(v, &gp);
   560 			GetNewVehiclePos(v, &gp);
   561 			SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos);
   561 			SetDisasterVehiclePos(v, gp.x, gp.y, v->z_pos);
   562 			return;
   562 			return;
   700 	if (v == NULL)
   700 	if (v == NULL)
   701 		return;
   701 		return;
   702 
   702 
   703 	/* Pick a random place, unless we find
   703 	/* Pick a random place, unless we find
   704 	    a small airport */
   704 	    a small airport */
   705 	x = (GET_TILE_X(Random())) * 16 + 8;
   705 	x = TileX(Random()) * 16 + 8;
   706 
   706 
   707 	FOR_ALL_STATIONS(st) {
   707 	FOR_ALL_STATIONS(st) {
   708 		if (st->xy && st->airport_tile != 0 &&
   708 		if (st->xy && st->airport_tile != 0 &&
   709 				st->airport_type <= 1 &&
   709 				st->airport_type <= 1 &&
   710 				IS_HUMAN_PLAYER(st->owner)) {
   710 				IS_HUMAN_PLAYER(st->owner)) {
   711 			x = (GET_TILE_X(st->xy) + 2) * 16;
   711 			x = (TileX(st->xy) + 2) * 16;
   712 			break;
   712 			break;
   713 		}
   713 		}
   714 	}
   714 	}
   715 
   715 
   716 	InitializeDisasterVehicle(v, x, 0, 135, 3, 0);
   716 	InitializeDisasterVehicle(v, x, 0, 135, 3, 0);
   730 	int x;
   730 	int x;
   731 
   731 
   732 	if (v == NULL)
   732 	if (v == NULL)
   733 		return;
   733 		return;
   734 
   734 
   735 	x = (GET_TILE_X(Random())) * 16 + 8;
   735 	x = TileX(Random()) * 16 + 8;
   736 
   736 
   737 	InitializeDisasterVehicle(v, x, 0, 135, 3, 2);
   737 	InitializeDisasterVehicle(v, x, 0, 135, 3, 2);
   738 	v->dest_tile = TILE_XY(MapSizeX() / 2, MapSizeY() / 2);
   738 	v->dest_tile = TILE_XY(MapSizeX() / 2, MapSizeY() / 2);
   739 	v->age = 0;
   739 	v->age = 0;
   740 
   740 
   769 	v = ForceAllocateSpecialVehicle();
   769 	v = ForceAllocateSpecialVehicle();
   770 	if (v == NULL)
   770 	if (v == NULL)
   771 		return;
   771 		return;
   772 
   772 
   773 	x = (MapSizeX() + 9) * 16 - 1;
   773 	x = (MapSizeX() + 9) * 16 - 1;
   774 	y = GET_TILE_Y(found->xy)*16 + 37;
   774 	y = TileY(found->xy) * 16 + 37;
   775 
   775 
   776 	InitializeDisasterVehicle(v,x,y, 135,1,4);
   776 	InitializeDisasterVehicle(v,x,y, 135,1,4);
   777 
   777 
   778 	u = ForceAllocateSpecialVehicle();
   778 	u = ForceAllocateSpecialVehicle();
   779 	if (u != NULL) {
   779 	if (u != NULL) {
   805 	v = ForceAllocateSpecialVehicle();
   805 	v = ForceAllocateSpecialVehicle();
   806 	if (v == NULL)
   806 	if (v == NULL)
   807 		return;
   807 		return;
   808 
   808 
   809 	x = -16 * 16;
   809 	x = -16 * 16;
   810 	y = GET_TILE_Y(found->xy)*16 + 37;
   810 	y = TileY(found->xy) * 16 + 37;
   811 
   811 
   812 	InitializeDisasterVehicle(v,x,y, 135,5,6);
   812 	InitializeDisasterVehicle(v,x,y, 135,5,6);
   813 
   813 
   814 	u = ForceAllocateSpecialVehicle();
   814 	u = ForceAllocateSpecialVehicle();
   815 	if (u != NULL) {
   815 	if (u != NULL) {
   831 	int x,y;
   831 	int x,y;
   832 
   832 
   833 	if (v == NULL)
   833 	if (v == NULL)
   834 		return;
   834 		return;
   835 
   835 
   836 	x = (GET_TILE_X(Random())) * 16 + 8;
   836 	x = TileX(Random()) * 16 + 8;
   837 
   837 
   838 	y = MapMaxX() * 16 - 1;
   838 	y = MapMaxX() * 16 - 1;
   839 	InitializeDisasterVehicle(v, x, y, 135, 7, 9);
   839 	InitializeDisasterVehicle(v, x, y, 135, 7, 9);
   840 	v->dest_tile = TILE_XY(MapSizeX() / 2, MapSizeY() / 2);
   840 	v->dest_tile = TILE_XY(MapSizeX() / 2, MapSizeY() / 2);
   841 	v->age = 0;
   841 	v->age = 0;
   859 
   859 
   860 	if (v == NULL)
   860 	if (v == NULL)
   861 		return;
   861 		return;
   862 
   862 
   863 	r = Random();
   863 	r = Random();
   864 	x = (GET_TILE_X(r)) * 16 + 8;
   864 	x = TileX(r) * 16 + 8;
   865 
   865 
   866 	y = 8;
   866 	y = 8;
   867 	dir = 3;
   867 	dir = 3;
   868 	if (r & 0x80000000) { y = MapMaxX() * 16 - 8 - 1; dir = 7; }
   868 	if (r & 0x80000000) { y = MapMaxX() * 16 - 8 - 1; dir = 7; }
   869 	InitializeDisasterVehicle(v, x, y, 0, dir,13);
   869 	InitializeDisasterVehicle(v, x, y, 0, dir,13);
   880 
   880 
   881 	if (v == NULL)
   881 	if (v == NULL)
   882 		return;
   882 		return;
   883 
   883 
   884 	r = Random();
   884 	r = Random();
   885 	x = (GET_TILE_X(r)) * 16 + 8;
   885 	x = TileX(r) * 16 + 8;
   886 
   886 
   887 	y = 8;
   887 	y = 8;
   888 	dir = 3;
   888 	dir = 3;
   889 	if (r & 0x80000000) { y = MapMaxX() * 16 - 8 - 1; dir = 7; }
   889 	if (r & 0x80000000) { y = MapMaxX() * 16 - 8 - 1; dir = 7; }
   890 	InitializeDisasterVehicle(v, x, y, 0, dir,14);
   890 	InitializeDisasterVehicle(v, x, y, 0, dir,14);