32
32
* Clear cells the_map.cells[x][y..y+len_y-1].
34
#define CLEAR_CELLS(x, y, len_y) do { \
34
#define CLEAR_CELLS(x, y, len_y) \
36
int clear_cells_i, j; \
36
37
memset(&the_map.cells[(x)][(y)], 0, sizeof(the_map.cells[(x)][(y)])*(len_y)); \
37
38
for (clear_cells_i = 0; clear_cells_i < (len_y); clear_cells_i++) \
39
the_map.cells[(x)][(y)+clear_cells_i].heads[0].size_x = 1; \
40
the_map.cells[(x)][(y)+clear_cells_i].heads[0].size_y = 1; \
41
the_map.cells[(x)][(y)+clear_cells_i].heads[1].size_x = 1; \
42
the_map.cells[(x)][(y)+clear_cells_i].heads[1].size_y = 1; \
43
the_map.cells[(x)][(y)+clear_cells_i].heads[2].size_x = 1; \
44
the_map.cells[(x)][(y)+clear_cells_i].heads[2].size_y = 1; \
40
for (j=0; j < MAXLAYERS; j++) { \
41
the_map.cells[(x)][(y)+clear_cells_i].heads[j].size_x = 1; \
42
the_map.cells[(x)][(y)+clear_cells_i].heads[j].size_y = 1; \
602
620
the_map.cells[px][py].need_update = 1;
603
621
if (the_map.cells[px][py].cleared) {
604
assert(MAXLAYERS == 3);
605
expand_clear_face_from_layer(px, py, 0);
606
expand_clear_face_from_layer(px, py, 1);
607
expand_clear_face_from_layer(px, py, 2);
622
assert(MAP1_LAYERS == 3);
623
expand_clear_face_from_layer(px, py, 0);
624
expand_clear_face_from_layer(px, py, 1);
625
expand_clear_face_from_layer(px, py, 2);
608
626
the_map.cells[px][py].darkness = 0;
609
627
the_map.cells[px][py].have_darkness = 0;
611
for (i = 0; i < MAXLAYERS; i++) {
629
for (i = 0; i < MAP1_LAYERS; i++) {
612
630
if (face[i] != -1) {
613
expand_set_face(px, py, i, face[i]);
631
expand_set_face(px, py, i, face[i], TRUE);
616
634
the_map.cells[px][py].cleared = 0;
636
set_darkness(px, py, 255-darkness);
640
/* tile is invisible (outside view area, i.e. big face update) */
642
for (i = 0; i < MAP1_LAYERS; i++) {
643
if (is_blank || face[i] != -1) {
644
expand_set_bigface(x, y, i, is_blank ? 0 : face[i], TRUE);
650
/* mapdate_clear_space() is used by Map2Cmd()
651
* Basically, server has told us there is nothing on
652
* this space. So clear it.
654
void mapdata_clear_space(int x, int y)
659
assert(0 <= x && x < MAX_VIEW);
660
assert(0 <= y && y < MAX_VIEW);
664
assert(0 <= px && px < FOG_MAP_SIZE);
665
assert(0 <= py && py < FOG_MAP_SIZE);
667
if (x < width && y < height) {
668
/* tile is visible */
670
/* visible tile is now blank ==> do not clear but mark as cleared */
671
if (!the_map.cells[px][py].cleared) {
672
the_map.cells[px][py].cleared = 1;
673
the_map.cells[px][py].need_update = 1;
675
for (i=0; i < MAXLAYERS; i++)
676
if (the_map.cells[px][py].heads[i].face)
677
expand_need_update_from_layer(px, py, i);
620
681
/* tile is invisible (outside view area, i.e. big face update) */
622
683
for (i = 0; i < MAXLAYERS; i++) {
623
if (is_blank || face[i] != -1) {
624
expand_set_bigface(x, y, i, is_blank ? 0 : face[i]);
684
expand_set_bigface(x, y, i, 0, TRUE);
690
/* With map2, we basically process a piece of data at a time. Thus,
691
* for each piece, we don't know what the final state of the space
692
* will be. So once Map2Cmd() has processed all the information for
693
* a space, it calls mapdata_set_check_space() which can see if
694
* the space is cleared or other inconsistencies.
696
void mapdata_set_check_space(int x, int y)
701
struct MapCell *cell;
703
assert(0 <= x && x < MAX_VIEW);
704
assert(0 <= y && y < MAX_VIEW);
709
assert(0 <= px && px < FOG_MAP_SIZE);
710
assert(0 <= py && py < FOG_MAP_SIZE);
714
cell = &the_map.cells[px][py];
715
for (i=0; i < MAXLAYERS; i++) {
716
if (cell->heads[i].face>0 || cell->tails[i].face>0) {
722
if (cell->have_darkness) is_blank=0;
724
/* We only care if this space needs to be blanked out */
725
if (!is_blank) return;
727
if (x < width && y < height) {
728
/* tile is visible */
730
/* visible tile is now blank ==> do not clear but mark as cleared */
731
if (!the_map.cells[px][py].cleared) {
732
the_map.cells[px][py].cleared = 1;
733
the_map.cells[px][py].need_update = 1;
735
for (i=0; i < MAXLAYERS; i++)
736
expand_need_update_from_layer(px, py, i);
743
/* This just sets the darkness for a space.
746
void mapdata_set_darkness(int x, int y, int darkness)
750
assert(0 <= x && x < MAX_VIEW);
751
assert(0 <= y && y < MAX_VIEW);
755
assert(0 <= px && px < FOG_MAP_SIZE);
756
assert(0 <= py && py < FOG_MAP_SIZE);
629
758
/* Ignore darkness information for tile outside the viewable area: if
630
759
* such a tile becomes visible again, it is either "fog of war" (and
768
/* Sets smooth information for layer */
769
void mapdata_set_smooth(int x, int y, int smooth, int layer)
771
static int dx[8]={0,1,1,1,0,-1,-1,-1};
772
static int dy[8]={-1,-1,0,1,1,1,0,-1};
773
int rx, ry, px, py, i;
775
assert(0 <= x && x < MAX_VIEW);
776
assert(0 <= y && y < MAX_VIEW);
780
assert(0 <= px && px < FOG_MAP_SIZE);
781
assert(0 <= py && py < FOG_MAP_SIZE);
783
if (the_map.cells[px][py].smooth[layer] != smooth) {
787
if ( (rx<0) || (ry<0) || (the_map.x<=rx) || (the_map.y<=ry))
789
the_map.cells[rx][ry].need_resmooth=1;
791
the_map.cells[px][py].need_resmooth=1;
792
the_map.cells[px][py].smooth[layer] = smooth;
796
/* This is vaguely related to the mapdata_set_face() above, but rather
797
* than take all the faces, takes 1 face and the layer this face is
798
* on. This is used by the Map2Cmd()
800
void mapdata_set_face_layer(int x, int y, sint16 face, int layer)
805
assert(0 <= x && x < MAX_VIEW);
806
assert(0 <= y && y < MAX_VIEW);
810
assert(0 <= px && px < FOG_MAP_SIZE);
811
assert(0 <= py && py < FOG_MAP_SIZE);
813
if (x < width && y < height) {
814
the_map.cells[px][py].need_update = 1;
815
if (the_map.cells[px][py].cleared) {
816
for (i=0; i < MAXLAYERS; i++)
817
expand_clear_face_from_layer(px, py, i);
819
the_map.cells[px][py].darkness = 0;
820
the_map.cells[px][py].have_darkness = 0;
823
expand_set_face(px, py, layer, face, TRUE);
825
expand_clear_face_from_layer(px, py, layer);
828
the_map.cells[px][py].cleared = 0;
831
expand_set_bigface(x, y, layer, face, TRUE);
836
/* This is vaguely related to the mapdata_set_face() above, but rather
837
* than take all the faces, takes 1 face and the layer this face is
838
* on. This is used by the Map2Cmd()
840
void mapdata_set_anim_layer(int x, int y, uint16 anim, uint8 anim_speed, int layer)
843
int i, face, animation, phase, speed_left;
845
assert(0 <= x && x < MAX_VIEW);
846
assert(0 <= y && y < MAX_VIEW);
850
assert(0 <= px && px < FOG_MAP_SIZE);
851
assert(0 <= py && py < FOG_MAP_SIZE);
853
animation = anim & ANIM_MASK;
856
/* Random animation is pretty easy */
857
if ((anim & ANIM_FLAGS_MASK) == ANIM_RANDOM) {
858
phase = random() % animations[animation].num_animations;
859
face = animations[animation].faces[phase];
860
speed_left = anim_speed % random();
861
} else if ((anim & ANIM_FLAGS_MASK) == ANIM_SYNC) {
862
animations[animation].speed = anim_speed;
863
phase = animations[animation].phase;
864
speed_left = animations[animation].speed_left;
865
face = animations[animation].faces[phase];
868
if (x < width && y < height) {
869
the_map.cells[px][py].need_update = 1;
870
if (the_map.cells[px][py].cleared) {
871
for (i=0; i < MAXLAYERS; i++)
872
expand_clear_face_from_layer(px, py, i);
874
the_map.cells[px][py].darkness = 0;
875
the_map.cells[px][py].have_darkness = 0;
878
expand_set_face(px, py, layer, face, TRUE);
879
the_map.cells[px][py].heads[layer].animation = animation;
880
the_map.cells[px][py].heads[layer].animation_phase = phase;
881
the_map.cells[px][py].heads[layer].animation_speed = anim_speed;
882
the_map.cells[px][py].heads[layer].animation_left = speed_left;
885
expand_clear_face_from_layer(px, py, layer);
888
the_map.cells[px][py].cleared = 0;
892
expand_set_bigface(x, y, layer, face, TRUE);
639
897
void mapdata_scroll(int dx, int dy)
1082
/* This is used by the opengl logic.
1083
* Basically the opengl code draws the the entire image,
1084
* and doesn't care if if portions are off the edge
1085
* (opengl takes care of that). So basically, this
1086
* function returns only if the head for a space is set,
1087
* otherwise, returns 0 - we don't care about the tails
1088
* or other details really.
1090
sint16 mapdata_bigface_head(int x, int y, int layer, int *ww, int *hh)
1094
if (width <= 0) return(0);
1096
assert(0 <= x && x < MAX_VIEW);
1097
assert(0 <= y && y < MAX_VIEW);
1098
assert(0 <= layer && layer < MAXLAYERS);
1100
result = bigfaces[x][y][layer].head.face;
1102
int w = bigfaces[x][y][layer].head.size_x;
1103
int h = bigfaces[x][y][layer].head.size_y;
825
1115
* Check if current map position is out of bounds if shifted by (dx, dy). If
826
1116
* so, shift the virtual map so that the map view is within bounds again.
1005
1295
if (*w > MAX_FACE_SIZE) *w = MAX_FACE_SIZE;
1006
1296
if (*h > MAX_FACE_SIZE) *h = MAX_FACE_SIZE;
1299
/* This basically goes through all the map spaces and does the necessary
1302
void mapdata_animation()
1304
int x, y, layer, face, smooth;
1305
struct MapCellLayer *cell;
1308
/* For synchronized animations, what we do is set the initial values
1309
* in the mapdata to the fields in the animations[] array. In this way,
1310
* the code below the iterates the spaces doesn't need to do anything
1311
* special. But we have to update the animations[] array here to
1314
for (x=0; x < MAXANIM; x++) {
1315
if (animations[x].speed) {
1316
animations[x].speed_left++;
1317
if (animations[x].speed_left >= animations[x].speed) {
1318
animations[x].speed_left=0;
1319
animations[x].phase++;
1320
if (animations[x].phase >= animations[x].num_animations)
1321
animations[x].phase=0;
1326
for (x=0; x < CURRENT_MAX_VIEW; x++) {
1327
for (y=0; y < CURRENT_MAX_VIEW; y++) {
1329
/* Short cut some processing here. It makes sense to me
1330
* not to animate stuff out of view
1332
if (the_map.cells[pl_pos.x + x][pl_pos.y + y].cleared) continue;
1334
for (layer=0; layer<MAXLAYERS; layer++) {
1335
smooth = the_map.cells[pl_pos.x + x][pl_pos.y + y].smooth[layer];
1337
/* Using the cell structure just makes life easier here */
1338
cell = &the_map.cells[pl_pos.x+x][pl_pos.y+y].heads[layer];
1340
if (cell->animation) {
1341
cell->animation_left++;
1342
if (cell->animation_left >= cell->animation_speed) {
1343
cell->animation_left=0;
1344
cell->animation_phase++;
1345
if (cell->animation_phase >= animations[cell->animation].num_animations)
1346
cell->animation_phase=0;
1347
face = animations[cell->animation].faces[cell->animation_phase];
1349
/* I don't think we send any to the client, but it is possible
1350
* for animations to have blank faces.
1353
expand_set_face(pl_pos.x + x, pl_pos.y + y, layer, face, FALSE);
1354
/* mapdata_set_smooth(x, y, smooth, layer);*/
1356
expand_clear_face_from_layer(pl_pos.x + x, pl_pos.y + y , layer);
1360
cell = &bigfaces[x][y][layer].head;
1361
if (cell->animation) {
1362
cell->animation_left++;
1363
if (cell->animation_left >= cell->animation_speed) {
1364
cell->animation_left=0;
1365
cell->animation_phase++;
1366
if (cell->animation_phase >= animations[cell->animation].num_animations)
1367
cell->animation_phase=0;
1368
face = animations[cell->animation].faces[cell->animation_phase];
1370
/* I don't think we send any to the client, but it is possible
1371
* for animations to have blank faces.
1373
expand_set_bigface(x, y, layer, face, FALSE);