forked from raduprv/Eternal-Lands
/
interface.c
1406 lines (1219 loc) · 36.3 KB
/
interface.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <SDL.h>
#include "interface.h"
#include "asc.h"
#include "bbox_tree.h"
#include "chat.h"
#include "consolewin.h"
#include "cursors.h"
#include "elwindows.h"
#include "elmemory.h"
#include "gamewin.h"
#include "gl_init.h"
#include "hud.h"
#include "langselwin.h"
#include "loginwin.h"
#include "map.h"
#include "mapwin.h"
#include "new_character.h"
#include "openingwin.h"
#include "pathfinder.h"
#include "rules.h"
#ifdef DEBUG_MAP_SOUND
#include "sound.h"
#endif // DEBUG_MAP_SOUND
#include "spells.h"
#include "textures.h"
#include "tiles.h"
#include "translate.h"
#include "update.h"
#include "weather.h"
#include "io/map_io.h"
#include "errors.h"
#include "io/elpathwrapper.h"
#include "io/elfilewrapper.h"
#include "3d_objects.h"
#ifdef NEW_TEXTURES
#include "image_loading.h"
#endif /* NEW_TEXTURES */
#define DEFAULT_CONTMAPS_SIZE 20
/* NOTE: This file contains implementations of the following, currently unused, and commented functions:
* Look at the end of the file.
*
* void draw_menu_title_bar(int, int, int);
*/
int mouse_x;
int mouse_y;
int right_click;
int middle_click;
int left_click;
char username_box_selected=1;
char password_box_selected=0;
char username_str[20]={0};
char password_str[20]={0};
char display_password_str[20]={0};
int username_text_length=0;
int password_text_length=0;
int have_a_map=0;
int combat_mode=0;
int auto_camera=0;
int view_health_bar=1;
int view_names=1;
int view_hp=0;
int view_chat_text_as_overtext=0;
int limit_fps=0;
int action_mode=ACTION_WALK;
Uint32 click_time=0;
GLdouble model_mat[16];
GLdouble projection_mat[16];
GLint viewport[4];
// Grum: attempt to work around bug in Ati linux drivers.
int ati_click_workaround = 0;
float mapmark_zoom=0.3f;
void save_scene_matrix ()
{
glGetDoublev (GL_MODELVIEW_MATRIX, model_mat);
glGetDoublev (GL_PROJECTION_MATRIX, projection_mat);
glGetIntegerv (GL_VIEWPORT, viewport);
}
void get_world_x_y (short *scene_x, short *scene_y)
{
double sx, sy, sz;
float mouse_z;
glReadPixels (mouse_x, window_height-mouse_y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &mouse_z);
// XXX FIXME (Grum): hack to work around a bug in the Ati drivers or
// a giant misconception on the part of all EL developers so far.
if (ati_click_workaround && bpp == 32)
mouse_z = ldexp (mouse_z, 8);
gluUnProject (mouse_x, window_height-hud_y-mouse_y, mouse_z, model_mat, projection_mat, viewport, &sx, &sy, &sz);
*scene_x = (sx / 0.5);
*scene_y = (sy / 0.5);
}
void get_old_world_x_y (short *scene_x, short *scene_y)
{
AABBOX box;
float t, x, y, z, t1, t2, tx, ty, dx, dy, h, len;
int i, j, h_max, h_min, h1, h2, h3, h4, sx, sy, zx, zy, i_min, i_max, j_min, j_max;
x = click_line.center[X];
y = click_line.center[Y];
z = click_line.center[Z];
dx = click_line.direction[X];
dy = click_line.direction[Y];
t = min2f(4.0f, max2f(-2.2f, z));
if (t != z)
{
t = (t-z)/click_line.direction[Z];
x += t*dx;
y += t*dy;
}
t = 6.2f / click_line.direction[Z];
len = min2f(max2f(t, -t), click_line.length);
len = click_line.length;
if (max2f(dx, -dx) < 0.000001f)
{
zx = 1;
sx = 0;
}
else
{
zx = 0;
if (dx < 0.0f) sx = -1;
else sx = 1;
}
if (max2f(dy, -dy) < 0.000001f)
{
zy = 1;
sy = 0;
}
else
{
zy = 0;
if (dy < 0.0f) sy = -1;
else sy = 1;
}
i = x*2.0f;
j = y*2.0f;
i_min = min2f(x, x+dx*len)*2.0f;
i_max = max2f(x, x+dx*len)*2.0f;
j_min = min2f(y, y+dy*len)*2.0f;
j_max = max2f(y, y+dy*len)*2.0f;
i_min = max2i(min2i(i_min, tile_map_size_x*6), 0);
i_max = max2i(min2i(i_max, tile_map_size_x*6-1), 0);
j_min = max2i(min2i(j_min, tile_map_size_y*6), 0);
j_max = max2i(min2i(j_max, tile_map_size_y*6-1), 0);
i = min2i(max2i(i, i_min), i_max-1);
j = min2i(max2i(j, j_min), j_max-1);
h = 0.0f;
while ((i >= i_min) && (j >= j_min) && (i < i_max) && (j < j_max))
{
h1 = height_map[j*tile_map_size_x*6+i];
h2 = height_map[j*tile_map_size_x*6+i+1];
h3 = height_map[(j+1)*tile_map_size_x*6+i];
h4 = height_map[(j+1)*tile_map_size_x*6+i+1];
h_max = max2i(max2i(h1, h2), max2i(h3, h4));
h_min = min2i(min2i(h1, h2), min2i(h3, h4));
tx = i*0.5f;
ty = j*0.5f;
box.bbmin[X] = tx;
box.bbmin[Y] = ty;
box.bbmin[Z] = h_min*0.2f-2.2f;
box.bbmax[X] = tx+1.0f;
box.bbmax[Y] = ty+1.0f;
box.bbmax[Z] = h_max*0.2f-2.2f;
if (click_line_bbox_intersection(box))
{
box.bbmin[X] = tx+0.0f;
box.bbmin[Y] = ty+0.0f;
box.bbmin[Z] = h1*0.2f-2.2f;
box.bbmax[X] = tx+0.5f;
box.bbmax[Y] = ty+0.5f;
box.bbmax[Z] = h1*0.2f-2.2f;
if (click_line_bbox_intersection(box))
{
h = h1*0.2f-2.2f;
break;
}
box.bbmin[X] = tx+0.5f;
box.bbmin[Y] = ty+0.0f;
box.bbmin[Z] = h2*0.2f-2.2f;
box.bbmax[X] = tx+1.0f;
box.bbmax[Y] = ty+0.5f;
box.bbmax[Z] = h2*0.2f-2.2f;
if (click_line_bbox_intersection(box))
{
h = h2*0.2f-2.2f;
break;
}
box.bbmin[X] = tx+0.0f;
box.bbmin[Y] = ty+0.5f;
box.bbmin[Z] = h3*0.2f-2.2f;
box.bbmax[X] = tx+0.5f;
box.bbmax[Y] = ty+1.0f;
box.bbmax[Z] = h3*0.2f-2.2f;
if (click_line_bbox_intersection(box))
{
h = h3*0.2f-2.2f;
break;
}
box.bbmin[X] = tx+0.5f;
box.bbmin[Y] = ty+0.5f;
box.bbmin[Z] = h4*0.2f-2.2f;
box.bbmax[X] = tx+1.0f;
box.bbmax[Y] = ty+1.0f;
box.bbmax[Z] = h4*0.2f-2.2f;
if (click_line_bbox_intersection(box))
{
h = h4*0.2f-2.2f;
break;
}
}
if ((zx == 1) && (zy == 1)) break;
if (zx == 0) t1 = (tx+sx-x)/dx;
else t1 = 10e30;
if (zx == 0) t2 = (ty+sy-y)/dy;
else t2 = -10e30;
if (t1 < t2) i += 2*sx;
else j += 2*sy;
t = min2f(t1, t2);
x += dx*t;
y += dy*t;
}
t = (h-click_line.center[Z])/click_line.direction[Z];
*scene_x = (click_line.center[X]+click_line.direction[X]*t) / 0.5;
*scene_y = (click_line.center[Y]+click_line.direction[Y]*t) / 0.5;
}
void Enter2DModeExtended(int width, int height)
{
#ifdef OPENGL_TRACE
CHECK_GL_ERRORS();
#endif //OPENGL_TRACE
if (use_fog) glDisable(GL_FOG);
glPushAttrib(GL_LIGHTING_BIT|GL_DEPTH_BUFFER_BIT);
glDisable(GL_LIGHTING);
glDisable(GL_DEPTH_TEST);
glViewport(0, 0, width, height);
#ifdef OPENGL_TRACE
CHECK_GL_ERRORS();
#endif //OPENGL_TRACE
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0.0, (GLdouble)width, (GLdouble)height, 0.0, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
#ifdef OPENGL_TRACE
CHECK_GL_ERRORS();
#endif //OPENGL_TRACE
}
void Enter2DMode()
{
Enter2DModeExtended(window_width, window_height);
}
void Leave2DMode()
{
#ifdef OPENGL_TRACE
CHECK_GL_ERRORS();
#endif //OPENGL_TRACE
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopAttrib();
glViewport(0, hud_y, window_width-hud_x, window_height-hud_y);
if (use_fog) glEnable(GL_FOG);
else glDisable(GL_FOG);
//glViewport(0, 0, window_width-hud_x, window_height-hud_y); // Reset The Current Viewport
#ifdef OPENGL_TRACE
CHECK_GL_ERRORS();
#endif //OPENGL_TRACE
}
/* The video modes start with index 1. So field 0 stands for video mode 1 */
video_mode_t video_modes[] = {
{ 640, 480, 16, NULL, { 0, 0}}, /* 1 */
{ 640, 480, 32, NULL, { 0, 0}}, /* 2 */
{ 800, 600, 16, NULL, { 0, 0}}, /* 3 */
{ 800, 600, 32, NULL, { 0, 0}}, /* 4 */
{1024, 768, 16, NULL, { 0, 0}}, /* 5 */
{1024, 768, 32, NULL, { 0, 0}}, /* 6 */
{1152, 864, 16, NULL, { 0, 0}}, /* 7 */
{1152, 864, 32, NULL, { 0, 0}}, /* 8 */
{1280, 1024, 16, NULL, { 0, 0}}, /* 9 */
{1280, 1024, 32, NULL, { 0, 0}}, /* 10 */
{1600, 1200, 16, NULL, { 0, 0}}, /* 11 */
{1600, 1200, 32, NULL, { 0, 0}}, /* 12 */
{1280, 800, 16, NULL, { 0, 0}}, /* 13 */
{1280, 800, 32, NULL, { 0, 0}}, /* 14 */
{1440, 900, 16, NULL, { 0, 0}}, /* 15 */
{1440, 900, 32, NULL, { 0, 0}}, /* 16 */
{1680, 1050, 16, NULL, { 0, 0}}, /* 17 */
{1680, 1050, 32, NULL, { 0, 0}}, /* 18 */
{1400, 1050, 16, NULL, { 0, 0}}, /* 19 */
{1400, 1050, 32, NULL, { 0, 0}}, /* 20 */
{ 800, 480, 16, NULL, { 0, 0}}, /* 21 */
{ 800, 480, 32, NULL, { 0, 0}}, /* 22 */
{1920, 1200, 16, NULL, { 0, 0}}, /* 23 */
{1920, 1200, 32, NULL, { 0, 0}}, /* 24 */
{1024, 600, 16, NULL, { 0, 0}}, /* 25 */
{1024, 600, 32, NULL, { 0, 0}}, /* 26 */
{1920, 1080, 16, NULL, { 0, 0}}, /* 27 */
{1920, 1080, 32, NULL, { 0, 0}}, /* 28 */
};
const int video_modes_count = sizeof(video_modes)/sizeof(*video_modes);
void build_video_mode_array()
{
int i;
int flags;
if (full_screen)
flags=SDL_OPENGL|SDL_FULLSCREEN;
else
flags=SDL_OPENGL;
for(i = 0; i < video_modes_count; i++)
{
video_modes[i].flags.selected = 0;
video_modes[i].flags.supported = 0;
if(bpp == video_modes[i].bpp
#ifdef WINDOWS
|| full_screen
#endif
)
{
if (SDL_VideoModeOK(video_modes[i].width, video_modes[i].height, video_modes[i].bpp, flags))
video_modes[i].flags.supported = 1;
}
}
if (video_mode > 0)
video_modes[video_mode-1].flags.selected=1;
}
void draw_console_pic(int which_texture)
{
#ifdef NEW_TEXTURES
bind_texture(which_texture);
glColor3f(1.0f,1.0f,1.0f);
glBegin(GL_QUADS);
//draw the texture
glTexCoord2f(0.0f, 0.0f);
glVertex3i(0,0,0);
glTexCoord2f(0.0f, 1.0f);
glVertex3i(0,window_height,0);
glTexCoord2f(1.0f, 1.0f);
glVertex3i(window_width,window_height,0);
glTexCoord2f(1.0f, 0.0f);
glVertex3i(window_width,0,0);
glEnd();
#else /* NEW_TEXTURES */
get_and_set_texture_id(which_texture);
glColor3f(1.0f,1.0f,1.0f);
glBegin(GL_QUADS);
//draw the texture
glTexCoord2f(0.0f,1.0f);
glVertex3i(0,0,0);
glTexCoord2f(0.0f,0.0f);
glVertex3i(0,window_height,0);
glTexCoord2f(1.0f,0.0f);
glVertex3i(window_width,window_height,0);
glTexCoord2f(1.0f,1.0f);
glVertex3i(window_width,0,0);
glEnd();
#endif /* NEW_TEXTURES */
#ifdef OPENGL_TRACE
CHECK_GL_ERRORS();
#endif //OPENGL_TRACE
}
void draw_2d_thing(float u_start,float v_start,float u_end,float v_end,int x_start,
int y_start,int x_end,int y_end)
{
glTexCoord2f(u_start,v_end);
glVertex3i(x_start,y_end,0);
glTexCoord2f(u_start,v_start);
glVertex3i(x_start,y_start,0);
glTexCoord2f(u_end,v_start);
glVertex3i(x_end,y_start,0);
glTexCoord2f(u_end,v_end);
glVertex3i(x_end,y_end,0);
}
void draw_2d_thing_r(float u_start,float v_start,float u_end,float v_end,int x_start,
int y_start,int x_end,int y_end)
{
glTexCoord2f(u_start,v_start);
glVertex3i(x_start,y_end,0);
glTexCoord2f(u_end,v_start);
glVertex3i(x_start,y_start,0);
glTexCoord2f(u_end,v_end);
glVertex3i(x_end,y_start,0);
glTexCoord2f(u_start,v_end);
glVertex3i(x_end,y_end,0);
}
void add_char_to_username(unsigned char ch)
{
if (((ch>=48 && ch<=57) || (ch>=65 && ch<=90) || (ch>=97 && ch<=122) || (ch=='_'))
&& username_text_length < MAX_USERNAME_LENGTH - 1) // MAX_USERNAME_LENGTH includes the null terminator
{
username_str[username_text_length]=ch;
username_str[username_text_length+1]=0;
username_text_length++;
}
if(ch==SDLK_DELETE || ch==SDLK_BACKSPACE)
{
if (username_text_length > 0)
username_text_length--;
else
username_text_length = 0;
username_str[username_text_length] = '\0';
}
}
void add_char_to_password(unsigned char ch)
{
if ((ch>=32 && ch<=126) && password_text_length < MAX_USERNAME_LENGTH - 1) // MAX_USERNAME_LENGTH includes the null terminator
{
password_str[password_text_length]=ch;
display_password_str[password_text_length]='*';
password_str[password_text_length+1]=0;
display_password_str[password_text_length+1]=0;
password_text_length++;
}
if (ch==SDLK_DELETE || ch==SDLK_BACKSPACE)
{
if (password_text_length > 0)
password_text_length--;
else
password_text_length = 0;
display_password_str[password_text_length] = '\0';
password_str[password_text_length] = '\0';
}
}
void draw_ingame_interface()
{
#ifdef OPENGL_TRACE
CHECK_GL_ERRORS();
#endif //OPENGL_TRACE
#ifdef OLD_CLOSE_BAG
// watch for closing a bag
if(ground_items_win >= 0)
{
int old_view= view_ground_items;
view_ground_items= get_show_window(ground_items_win);
// watch for telling the server we need to close the bag
if(old_view && !view_ground_items)
{
unsigned char protocol_name;
protocol_name= S_CLOSE_BAG;
my_tcp_send(my_socket,&protocol_name,1);
}
}
#endif //OLD_CLOSE_BAG
glColor3f(1.0f, 1.0f, 1.0f);
draw_hud_frame();
//draw_hud_interface();
display_spells_we_have();
#ifdef OPENGL_TRACE
CHECK_GL_ERRORS();
#endif //OPENGL_TRACE
}
GLuint map_text;
static int cont_text = -1; // index in texture cache for continent map
GLuint inspect_map_text = 0;
int show_continent_map_boundaries = 1;
GLuint legend_text=0;
int cur_map; //Is there a better way to do this?
#ifdef DEBUG_MAP_SOUND
int cur_tab_map = -1;
#endif // DEBUG_MAP_SOUND
#ifdef NEW_TEXTURES
static const char* cont_map_file_names[] =
{
"./maps/seridia",
"./maps/irilion"
};
#else /* NEW_TEXTURES */
static const char* cont_map_file_names[] = {
"./maps/seridia.bmp",
"./maps/irilion.bmp"
};
#endif /* NEW_TEXTURES */
static const int nr_continents = sizeof (cont_map_file_names) / sizeof (const char *);
struct draw_map *continent_maps = NULL;
void read_mapinfo ()
{
FILE *fin;
char line[256];
int maps_size, imap;
char *cmt_pos;
char cont_name[64];
unsigned short continent, x_start, y_start, x_end, y_end;
char map_name[128];
maps_size = DEFAULT_CONTMAPS_SIZE;
continent_maps = calloc (maps_size, sizeof (struct draw_map));
imap = 0;
fin = open_file_data ("mapinfo.lst", "r");
if (fin == NULL){
LOG_ERROR("%s: %s \"mapinfo.lst\"\n", reg_error_str, cant_open_file);
} else {
while (fgets (line, sizeof (line), fin) != NULL)
{
// strip comments
cmt_pos = strchr (line, '#');
if (cmt_pos != NULL)
*cmt_pos = '\0';
if (sscanf (line, "%63s %hu %hu %hu %hu %127s ", cont_name, &x_start, &y_start, &x_end, &y_end, map_name) != 6)
// not a valid line
continue;
if (strcasecmp (cont_name, "Seridia") == 0)
continent = 0;
else if (strcasecmp (cont_name, "Irilion") == 0)
continent = 1;
else
// not a valid continent
continue;
if (imap >= maps_size - 1)
{
// Uh oh, we didn't allocate enough space
maps_size += DEFAULT_CONTMAPS_SIZE;
continent_maps = realloc (continent_maps, maps_size * sizeof (struct draw_map));
}
continent_maps[imap].cont = continent;
continent_maps[imap].x_start = x_start;
continent_maps[imap].y_start = y_start;
continent_maps[imap].x_end = x_end;
continent_maps[imap].y_end = y_end;
continent_maps[imap].name = malloc ((strlen (map_name) + 1) * sizeof (char));
strcpy(continent_maps[imap].name, map_name);
imap++;
}
fclose (fin);
}
continent_maps[imap].cont = 0;
continent_maps[imap].x_start = 0;
continent_maps[imap].y_start = 0;
continent_maps[imap].x_end = 0;
continent_maps[imap].y_end = 0;
continent_maps[imap].name = NULL;
}
int switch_to_game_map()
{
#ifdef NEW_TEXTURES
char buffer[1024];
#else /* NEW_TEXTURES */
int len;
texture_cache_struct tex;
#endif /* NEW_TEXTURES */
short int cur_cont;
static short int old_cont = -1;
/* check we loaded the mapinfo data */
if (continent_maps == NULL || continent_maps[0].name == NULL)
{
LOG_TO_CONSOLE(c_yellow2,err_nomap_str);
return 0;
}
#ifdef NEW_TEXTURES
if (check_image_name(map_file_name, sizeof(buffer), buffer) == 1)
{
map_text = load_texture_cached(buffer, tt_image);
}
else
{
map_text = 0;
}
#else /* NEW_TEXTURES */
my_strcp(tex.file_name,map_file_name);
len=strlen(tex.file_name);
tex.file_name[len-3]='b';
tex.file_name[len-2]='m';
tex.file_name[len-1]='p';
tex.alpha = 128;
if (!el_file_exists(tex.file_name))
map_text = 0;
else
map_text=load_bmp8_fixed_alpha(&tex, tex.alpha);
#endif /* NEW_TEXTURES */
if(!map_text)
{
LOG_TO_CONSOLE(c_yellow2,err_nomap_str);
return 0;
}
if (cur_map < 0)
{
cur_cont = -1;
}
else
{
cur_cont = continent_maps[cur_map].cont;
}
if (cur_cont != old_cont && cur_cont >= 0 && cur_cont < nr_continents)
{
#ifdef NEW_TEXTURES
cont_text = load_texture_cached (cont_map_file_names[cur_cont], tt_image);
#else /* NEW_TEXTURES */
cont_text = load_texture_cache (cont_map_file_names[cur_cont], 128);
#endif /* NEW_TEXTURES */
old_cont = cur_cont;
}
#ifdef DEBUG_MAP_SOUND
cur_tab_map = cur_map;
#endif // DEBUG_MAP_SOUND
if(current_cursor != CURSOR_ARROW)
{
change_cursor(CURSOR_ARROW);
}
return 1;
}
void switch_from_game_map()
{
#ifndef NEW_TEXTURES
glDeleteTextures(1,&map_text);
#ifdef OPENGL_TRACE
CHECK_GL_ERRORS();
#endif //OPENGL_TRACE
#endif /* NEW_TEXTURES */
}
static void draw_mark_filter(void)
{
int screen_x=0;
int screen_y=0;
// display the Mark filter title
glColor3f(1.0f,1.0f,0.0f);
screen_x = 25 - 1.5*strlen(label_mark_filter);
screen_y = 150 + 22;
draw_string_zoomed(screen_x, screen_y, (unsigned char*)label_mark_filter, 1, 0.3);
// if filtering marks, display the label and the current filter text
if (mark_filter_active) {
char * show_mark_filter_text;
int max_show_len = 15;
if (strlen(mark_filter_text) > max_show_len)
show_mark_filter_text = &mark_filter_text[strlen(mark_filter_text)-max_show_len];
else if (strlen(mark_filter_text) == 0)
show_mark_filter_text = "_";
else
show_mark_filter_text = mark_filter_text;
screen_x = 25 - 1.5*strlen(show_mark_filter_text);
screen_y = 150 + 29;
draw_string_zoomed(screen_x, screen_y, (unsigned char*)show_mark_filter_text, 1, 0.3);
}
// display which key to activate the filter
else
{
char buf[20];
get_key_string(K_MARKFILTER, buf, sizeof(buf));
draw_string_zoomed(25 - 1.5*strlen(buf), 150 + 29, (const unsigned char *)buf, 1, 0.3);
}
}
static void draw_marks(marking *the_marks, int the_max_mark, int the_tile_map_size_x, int the_tile_map_size_y)
{
size_t i;
int screen_x=0;
int screen_y=0;
// crave the markings
for(i=0;i<the_max_mark;i++)
{
int x = the_marks[i].x;
int y = the_marks[i].y;
if ( x > 0 ) {
// if filtering marks, don't display if it doesn't match the current filter
if (mark_filter_active
&& (get_string_occurance(mark_filter_text, the_marks[i].text, strlen(the_marks[i].text), 1) == -1))
continue;
screen_x=(51+200*x/(the_tile_map_size_x*6));
screen_y=201-200*y/(the_tile_map_size_y*6);
if(!the_marks[i].server_side) glColor3f((float)the_marks[i].r/255,(float)the_marks[i].g/255,(float)the_marks[i].b/255);//glColor3f(0.4f,1.0f,0.0f);
else glColor3f(0.33f,0.6f,1.0f);
glDisable(GL_TEXTURE_2D);
glBegin(GL_LINES);
glVertex2i(screen_x-9*mapmark_zoom,screen_y-9*mapmark_zoom);
glVertex2i(screen_x+6*mapmark_zoom,screen_y+6*mapmark_zoom);
glVertex2i(screen_x+6*mapmark_zoom,screen_y-9*mapmark_zoom);
glVertex2i(screen_x-9*mapmark_zoom,screen_y+6*mapmark_zoom);
glEnd();
glEnable(GL_TEXTURE_2D);
if(!the_marks[i].server_side) glColor3f((float)the_marks[i].r/255,(float)the_marks[i].g/255,(float)the_marks[i].b/255);//glColor3f(0.2f,1.0f,0.0f);
else glColor3f(0.33f,0.6f,1.0f);
draw_string_zoomed(screen_x, screen_y, (unsigned char*)the_marks[i].text, 1, mapmark_zoom);
}
}
}
void draw_coordinates(int the_tile_map_size_x, int the_tile_map_size_y)
{
int screen_x=0;
int screen_y=0;
int map_x, map_y;
// draw coordinates
if (pf_get_mouse_position_extended(mouse_x, mouse_y, &map_x, &map_y, the_tile_map_size_x, the_tile_map_size_y)) {
// we're pointing on the map, display position
char buf[10];
safe_snprintf(buf, sizeof(buf), "%d,%d", map_x, map_y);
glColor3f(1.0f,1.0f,0.0f);
screen_x = 25 - 1.5*strlen(buf);
screen_y = 150 + 8;
draw_string_zoomed(screen_x, screen_y, (unsigned char*)buf, 1, 0.3);
screen_x = 25 - 1.5*strlen(label_cursor_coords);
screen_y = 150 + 1;
draw_string_zoomed(screen_x, screen_y, (unsigned char*)label_cursor_coords, 1, 0.3);
}
}
void draw_game_map (int map, int mouse_mini)
{
int screen_x=0;
int screen_y=0;
int x=-1,y=-1;
float x_size=0,y_size=0;
GLuint map_small, map_large;
actor *me;
static int fallback_text = -1;
// if we don't have a continent texture (instance may be), fallback to blank paper
if (cont_text < 0)
{
if (fallback_text < 0)
#ifdef NEW_TEXTURES
{
fallback_text = load_texture_cached("./textures/paper1", tt_gui);
}
#else /* NEW_TEXTURES */
fallback_text = load_texture_cache ("./textures/paper1.bmp", 0);
#endif /* NEW_TEXTURES */
cont_text = fallback_text;
}
if(map){
#ifdef NEW_TEXTURES
map_small = cont_text;
#else /* NEW_TEXTURES */
map_small=get_texture_id(cont_text);
#endif /* NEW_TEXTURES */
if(inspect_map_text == 0) {
map_large=map_text;
} else {
map_large = inspect_map_text;
}
} else {
map_small=map_text;
#ifdef NEW_TEXTURES
map_large = cont_text;
#else /* NEW_TEXTURES */
map_large=get_texture_id(cont_text);
#endif /* NEW_TEXTURES */
if(cur_map!=-1){
x_size = ((float)(continent_maps[cur_map].x_end - continent_maps[cur_map].x_start)) / tile_map_size_x;
y_size = ((float)(continent_maps[cur_map].y_end - continent_maps[cur_map].y_start)) / tile_map_size_y;
} else {
x_size=y_size=0;
}
}
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
glViewport(0, 0 + hud_y, window_width-hud_x, window_height-hud_y);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(300, (GLdouble)0, (GLdouble)0, 200, -250.0, 250.0);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glDisable(GL_TEXTURE_2D);
glColor3f(0.0f, 0.0f, 0.0f);
glBegin(GL_QUADS);
glVertex2i(0, 0);
glVertex2i(300, 0);
glVertex2i(300, 200);
glVertex2i(0, 200);
glEnd();
glEnable(GL_TEXTURE_2D);
glColor3f(1.0f,1.0f,1.0f);
#ifdef NEW_TEXTURES
bind_texture(map_large);
glBegin(GL_QUADS);
glTexCoord2f(1.0f, 1.0f); glVertex3i(50,0,0);
glTexCoord2f(1.0f, 0.0f); glVertex3i(50,200,0);
glTexCoord2f(0.0f, 0.0f); glVertex3i(250,200,0);
glTexCoord2f(0.0f, 1.0f); glVertex3i(250,0,0);
glEnd();
#else /* NEW_TEXTURES */
bind_texture_id(map_large);
glBegin(GL_QUADS);
glTexCoord2f(1.0f,0.0f); glVertex3i(50,0,0);
glTexCoord2f(1.0f,1.0f); glVertex3i(50,200,0);
glTexCoord2f(0.0f,1.0f); glVertex3i(250,200,0);
glTexCoord2f(0.0f,0.0f); glVertex3i(250,0,0);
glEnd();
#endif /* NEW_TEXTURES */
if (mouse_mini)
glColor4f (1.0f, 1.0f, 1.0f, 1.0f);
else
glColor4f (0.7f, 0.7f, 0.7f, 0.7f);
glEnable(GL_ALPHA_TEST);
#ifdef NEW_TEXTURES
bind_texture(map_small);
glBegin(GL_QUADS);
glTexCoord2f(1.0f, 1.0f); glVertex3i(250,150,0);
glTexCoord2f(1.0f, 0.0f); glVertex3i(250,200,0);
glTexCoord2f(0.0f, 0.0f); glVertex3i(300,200,0);
glTexCoord2f(0.0f, 1.0f); glVertex3i(300,150,0);
glEnd();
#else /* NEW_TEXTURES */
bind_texture_id(map_small);
glBegin(GL_QUADS);
glTexCoord2f(1.0f,0.0f); glVertex3i(250,150,0);
glTexCoord2f(1.0f,1.0f); glVertex3i(250,200,0);
glTexCoord2f(0.0f,1.0f); glVertex3i(300,200,0);
glTexCoord2f(0.0f,0.0f); glVertex3i(300,150,0);
glEnd();
#endif /* NEW_TEXTURES */
glDisable(GL_ALPHA_TEST);
glColor3f(1.0f,1.0f,1.0f);
#ifdef NEW_TEXTURES
bind_texture(legend_text);
glBegin(GL_QUADS);
glTexCoord2f(1.0f, 1.0f); glVertex3i(250,50,0);
glTexCoord2f(1.0f, 0.0f); glVertex3i(250,150,0);
glTexCoord2f(0.0f, 0.0f); glVertex3i(300,150,0);
glTexCoord2f(0.0f, 1.0f); glVertex3i(300,50,0);
glEnd();
#else /* NEW_TEXTURES */
get_and_set_texture_id(legend_text);
glBegin(GL_QUADS);
glTexCoord2f(1.0f,0.0f); glVertex3i(250,50,0);
glTexCoord2f(1.0f,1.0f); glVertex3i(250,150,0);
glTexCoord2f(0.0f,1.0f); glVertex3i(300,150,0);
glTexCoord2f(0.0f,0.0f); glVertex3i(300,50,0);
glEnd();
#endif /* NEW_TEXTURES */
// this is necessary for the text over map
// need to execute this for any map now
// because of the coordinate display - Lachesis
if(map/*&&(adding_mark||max_mark>0)*/){
glViewport(0, 0 + hud_y, window_width-hud_x, window_height-hud_y);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho((GLdouble)0, (GLdouble)300, (GLdouble)200, (GLdouble)0, -250.0, 250.0);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
// Draw help for toggling the mini-map
{
char buf[80];
char keybuf[20];
glEnable(GL_TEXTURE_2D);
safe_snprintf(buf, sizeof(buf), "%s %s", win_minimap, get_key_string(K_MINIMAP, keybuf, sizeof(keybuf)));
glColor3f (1.0f, 1.0f, 0.0f);
draw_string_zoomed(25 - 1.5*strlen(buf), 150 + 43, (const unsigned char *)buf, 1, 0.3);
}
// draw a temporary mark until the text is entered
if (adding_mark) {
int x = mark_x;
int y = mark_y;
screen_x=(51+200*x/(tile_map_size_x*6));
screen_y=201-200*y/(tile_map_size_y*6);
glColor3f(1.0f,1.0f,0.0f);
glDisable(GL_TEXTURE_2D);
glBegin(GL_LINES);
glVertex2i(screen_x-9*mapmark_zoom,screen_y-9*mapmark_zoom);
glVertex2i(screen_x+6*mapmark_zoom,screen_y+6*mapmark_zoom);
glVertex2i(screen_x+6*mapmark_zoom,screen_y-9*mapmark_zoom);
glVertex2i(screen_x-9*mapmark_zoom,screen_y+6*mapmark_zoom);
glEnd();
glEnable(GL_TEXTURE_2D);
glColor3f(1.0f,1.0f,0.0f);
draw_string_zoomed (screen_x, screen_y, (unsigned char*)input_text_line.data, 1, mapmark_zoom);
}
draw_mark_filter();
if(inspect_map_text == 0) {
draw_marks(marks, max_mark, tile_map_size_x, tile_map_size_y);
draw_coordinates(tile_map_size_x, tile_map_size_y);
}
else {
draw_marks(temp_marks, max_temp_mark, temp_tile_map_size_x, temp_tile_map_size_y);
draw_coordinates(temp_tile_map_size_x, temp_tile_map_size_y);
}
}
//if we're following a path, draw the destination on the map
if (pf_follow_path && inspect_map_text == 0)
{
int px = pf_dst_tile->x;
int py = pf_dst_tile->y;
if (!map)
{