-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgame.c
10154 lines (8145 loc) · 258 KB
/
game.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
/*
Author: Mike Bok
Email: [email protected]
Website: www.nighsoft.net
License and Rights: Full licensing and Rights available at www.nighsoft.net.
If licensing and rights not available at www.nighsoft.net, then all the following apply as bulleted:
-all rights reserved.
-you can not modify source code in this file.
-you can compile and use this source code.
*/
#include "main.h"
void draw_space_user_ship ( int i );
char *good_description ( int good_number, char *dest );
void clear_user_misc ( int i )
{
int k;
for ( k=0;k<16;k++ )
{
game.ship[i].gun[k] = -1;
game.ship[i].gun_id[k] = -1;
game.ship[i].missile[k] = -1;
game.ship[i].missile_id[k] = -1;
game.ship[i].misc[k] = -1;
game.ship[i].misc_id[k] = -1;
}
}
void set_user_misc() //this func applys misc-pod changes
{
int i, temp_misc;
game.ship[game.ship_sel].cargo = game.ship[game.ship_sel].cargo_base; //set back to initials
game.ship[game.ship_sel].hull_max = game.ship[game.ship_sel].hull_base;
game.ship[game.ship_sel].speed = game.ship[game.ship_sel].speed_base;
game.ship[game.ship_sel].shield = game.ship[game.ship_sel].shield_base;
for ( i=0;i<game.ship[game.ship_sel].misc_ammount;i++ )
{
temp_misc = game.ship[game.ship_sel].misc[i];
while ( temp_misc > 3 )
temp_misc -= 4;
if ( temp_misc < 0 ) //skip this entry if invalid
continue;
switch ( temp_misc )
{
case 0: //hull
game.ship[game.ship_sel].hull_max += misc_pod_value ( game.ship[game.ship_sel].misc[i] );
break;
case 1: //shield
game.ship[game.ship_sel].shield += misc_pod_value ( game.ship[game.ship_sel].misc[i] );
break;
case 2: //cargo
game.ship[game.ship_sel].cargo += misc_pod_value ( game.ship[game.ship_sel].misc[i] );
break;
case 3: //jump
game.ship[game.ship_sel].speed += misc_pod_value ( game.ship[game.ship_sel].misc[i] );
break;
}
}
//set jump_time for the launched screen
set_user_jump_time();
}
void set_user_jump_time()
{
int sh_sel;
sh_sel = game.ship_sel;
space.jump_time = ship_total_seconds ( game.ship[sh_sel].speed, game.ship[sh_sel].kind );
}
void add_chat ( int text_color, char *message )
{
if ( check_ignore_normal ( text_color, message ) ) return;
if ( bar.visible )
{
add_display_box ( screen, &bar.display_box[0], text_color, message );
sdl_flip_mutex();
}
if ( space.visible )
{
add_display_box ( screen, &space.display_box[0], text_color, message );
sdl_flip_mutex();
}
if ( map.visible )
{
add_display_box ( NULL, &space.display_box[0], text_color, message );
sdl_flip_mutex();
}
}
void add_private_chat ( int text_color, char *message )
{
if ( check_ignore_private ( text_color, message ) ) return;
if ( bar.visible )
{
add_display_box ( screen, &bar.display_box[1], text_color, message );
add_display_box ( NULL, &space.display_box[1], text_color, message );
sdl_flip_mutex();
}
else if ( space.visible )
{
add_display_box ( screen, &space.display_box[1], text_color, message );
add_display_box ( NULL, &bar.display_box[1], text_color, message );
sdl_flip_mutex();
}
else //add to but dont write to screen
{
add_display_box ( NULL, &bar.display_box[1], text_color, message );
add_display_box ( NULL, &space.display_box[1], text_color, message );
}
}
void clear_space_user_struct ( struct space_user *the_user )
{
int i;
the_user->ship_id = -1;
the_user->ship_kind = -1;
the_user->ship_type = -1;
the_user->ship_name[0] = '\0';
the_user->username[0] = '\0';
the_user->guild[0] = '\0';
the_user->destroy = 0;
the_user->hull_percent = 100;
the_user->attacking = -1;
the_user->shield_level = 0;
the_user->refresh_shield= 1;
the_user->jump_status = 0;
the_user->sos = 0;
for ( i=0;i<16;i++ )
the_user->missile_firing[i] = 0;
}
void load_sector ( int new_zone, int new_sector, char *user_list )
{
int i, point = 0, user_len, user_limit, temp_loc;
char temp_str[1025];
struct space_user temp_usr;
if ( new_zone < 0 || new_zone >= ZONE_MAX ) return; //client killer!
if ( new_sector < 0 || new_sector >= SECTOR_MAX ) return; //client killer!
//ehh sound
if ( !launching.visible )
play_sound ( sound_jump );
//god this is anouying
if ( !space.viewing_cargo )
{
space_clear_middle_box();
space.show_ship = 1;
}
//get these buttons ready
space.draw_goods_grey = 1;
space.draw_contra_grey = 1;
//remove any users that may be selected in space
space.user_sel = -1;
//we also arent attacking anyone yet
space.engaging = -1;
//just doesnt need to be done
space.clear_jump_bar = 0;
//missiles shouldnt be firing...
for ( i=0;i<16;i++ )
space.missile_firing[i] = 0;
//check if sector has a planet
if ( server[game.server_id].zone[new_zone].sector[new_sector].planet > -1 )
{
space.at_planet = 1;
user_limit = 39;
}
else
{
space.at_planet = 0;
user_limit = 40;
}
//clear user information
space.user_ammount = 0;
for ( i=0;i<40;i++ )
clear_space_user_struct ( & ( space.user[i] ) );
//load user information
user_len = strlen ( user_list );
for ( i=0;point<user_len && i<user_limit;i++ )
{
clear_space_user_struct ( &temp_usr );
//ship id,type,kind,class_name,user_name,user_guild
split ( temp_str, user_list, ',', &point );
temp_usr.ship_id = atoi ( temp_str );
split ( temp_str, user_list, ',', &point );
temp_usr.ship_type = atoi ( temp_str );
split ( temp_str, user_list, ',', &point );
temp_usr.ship_kind = atoi ( temp_str );
split ( temp_str, user_list, ',', &point );
temp_str[20] = '\0';
strcpy ( temp_usr.ship_name, temp_str );
split ( temp_str, user_list, ',', &point );
temp_str[20] = '\0';
strcpy ( temp_usr.username, temp_str );
split ( temp_str, user_list, ',', &point );
temp_str[20] = '\0';
strcpy ( temp_usr.guild, temp_str );
//check if field type
if ( temp_usr.ship_type == -2 )
{
temp_usr.ship_type = temp_usr.ship_kind + SHIP_MAX;
temp_usr.ship_kind = 0;
}
//check if valid
if ( temp_usr.ship_id < -2 || temp_usr.ship_id >= MAX_SERVER ) continue;
if ( temp_usr.ship_type < 0 || temp_usr.ship_type >= SHIP_MAX + FIELD_TYPE_MAX ) continue;
if ( temp_usr.ship_kind < 0 || temp_usr.ship_kind >= 8 ) continue;
//check for special per designed "ships"
if ( temp_usr.ship_id == -1 && ( temp_usr.ship_kind >= SPECIAL_FSHIP_MAX || temp_usr.ship_kind < 0 ) ) continue;
//runes
if ( temp_usr.ship_id == -2 && ( temp_usr.ship_type > 3 ) ) continue;
//set this number
space.user_ammount++;
//give random "image"
temp_usr.image = rand() % 5;
//is sos?
if ( check_sos_raw ( temp_usr.username ) > -1 )
temp_usr.sos = 1;
//stuff that needs set...
temp_usr.destroy = 0;
temp_usr.hull_percent = 100;
temp_usr.attacking = -1;
temp_usr.attack_x = 0;
temp_usr.attack_y = 0;
temp_usr.attack_position = 0;
//find random place to put.
while ( 1 ) //loop until found
{
if ( space.at_planet )
temp_loc = ( rand() % 39 ) + 1;
else
temp_loc = rand() % 40;
if ( space.user[temp_loc].ship_id == -1 && !space_user_is_special ( temp_loc ) )
{
space.user[temp_loc] = temp_usr;
break;
}
}
}
//load loc and posibly planet
load_sector_loc ( game.server_id, new_zone, new_sector );
//place any users on the loc
space.redraw_loc = 1;
//reset some things...
space.jump_ok = 0;
map.scan_sector = -1;
space.jump_time_start = current_time();
//set this
game.sector = new_sector;
game.zone = new_zone;
//reset this hell
map.shift_x = 0;
map.shift_y = 0;
map.do_shift = 0;
//set sector links
map_set_local_sector_info();
//display a little warning
strcpy ( temp_str,"... Warning : Entering sun's radius .." );
if ( server[game.server_id].zone[game.zone].sector[game.sector].sun_damage )
add_chat ( 1,temp_str );
load_space();
}
void load_sector_locs_safe ( int s_id, int z )
{
int i;
char temp_str[1025];
if ( !server[s_id].zone[z].loc_safe[0] ) //if image not loaded
for ( i=0;i<LOC_MAX;i++ ) //then load em up
{
sprintf ( temp_str, "server/%s/backs/locs/safe%d_%d.jpg", server[s_id].servername, z, i + 1 );
server[s_id].zone[z].loc_safe[i] = IMG_Load ( temp_str );
//check if we hit the end of the line
if ( !server[s_id].zone[z].loc_safe[i] )
{
server[s_id].zone[z].loc_safe_max = i;
break;
}
}
//still not loaded... nif time
if ( !server[s_id].zone[z].loc_safe[0] )
{
if ( !game.nif_image.no_loc_safe_img )
game.nif_image.no_loc_safe_img = IMG_Load ( "graphics/nif/nif_safe_loc.jpg" );
server[s_id].zone[z].loc_safe[0] = game.nif_image.no_loc_safe_img;
server[s_id].zone[z].loc_safe_max = 1;
}
}
void load_sector_locs ( int s_id, int z )
{
int i;
char temp_str[1025];
if ( !server[s_id].zone[z].loc[0] ) //if image not loaded
for ( i=0;i<LOC_MAX;i++ ) //then load em up
{
sprintf ( temp_str, "server/%s/backs/locs/loc%d_%d.jpg", server[s_id].servername, z, i + 1 );
server[s_id].zone[z].loc[i] = IMG_Load ( temp_str );
//check if we hit the end of the line
if ( !server[s_id].zone[z].loc[i] )
{
server[s_id].zone[z].loc_max = i;
break;
}
}
//still not loaded... nif time
if ( !server[s_id].zone[z].loc[0] )
{
if ( !game.nif_image.no_loc_img )
game.nif_image.no_loc_img = IMG_Load ( "graphics/nif/nif_loc.jpg" );
server[s_id].zone[z].loc[0] = game.nif_image.no_loc_img;
server[s_id].zone[z].loc_max = 1;
}
}
void draw_sector_loc ( int s_id, int z, int s, SDL_Surface *the_loc )
{
char temp_str[1025];
SDL_BlitSurface ( the_loc, NULL, space.loc, NULL );
if ( space.at_planet ) //check if we need to put the planet image on top...
{
space.last_loc_planet = server[s_id].zone[z].sector[s].planet;
space.was_sun = 0;
if ( !server[s_id].planet[space.last_loc_planet].loc_img ) // not found so load it
{
sprintf ( temp_str, "server/%s/backs/locs/p%d_1.gif", server[s_id].servername, space.last_loc_planet );
server[s_id].planet[space.last_loc_planet].loc_img = IMG_Load ( temp_str );
}
if ( !server[s_id].planet[space.last_loc_planet].loc_img ) // still not found so load it
{
if ( !game.nif_image.no_loc_p_img )
game.nif_image.no_loc_p_img = IMG_Load ( "graphics/nif/nif_p.gif" );
SDL_BlitSurface ( game.nif_image.no_loc_p_img, NULL, space.loc, NULL );
}
else //use the real image
{
SDL_BlitSurface ( server[s_id].planet[space.last_loc_planet].loc_img, NULL, space.loc, NULL );
}
}
else
{
if ( server[s_id].zone[z].sector[s].is_sun )
{
SDL_BlitSurface ( space.loc_sun, NULL, space.loc, NULL );
space.was_sun = 1;
}
else
{
space.was_sun = 0;
}
space.last_loc_planet = -1;
}
}
void load_sector_loc ( int s_id, int z, int s )
{
int i, temp_loc;
char temp_str[1025];
if ( server[s_id].zone[z].sector[s].shield ) //if zone is a safe area
{
load_sector_locs_safe ( s_id, z );
temp_loc = rand() % ( server[s_id].zone[z].loc_safe_max );
//check if useing the new loc is required
if ( server[s_id].zone[z].sector[s].is_sun != space.was_sun || server[s_id].zone[z].sector[s].planet != space.last_loc_planet || z != space.last_loc_zone || !space.last_loc_safe )
{
draw_sector_loc ( s_id, z, s, server[s_id].zone[z].loc_safe[temp_loc] );
space.last_loc_number = temp_loc;
space.last_loc_safe = 1;
space.last_loc_zone = z;
}
else //not required so we'll roll the dice.
{
if ( ! ( rand() % 3 ) && space.last_loc_number != temp_loc ) //1 in 3
{
draw_sector_loc ( s_id, z, s, server[s_id].zone[z].loc_safe[temp_loc] );
space.last_loc_number = temp_loc;
space.last_loc_safe = 1;
space.last_loc_zone = z;
}
}
}
else // not a safe area...
{
load_sector_locs ( s_id, z );
temp_loc = rand() % ( server[s_id].zone[z].loc_max );
//check if useing the new loc is required
if ( server[s_id].zone[z].sector[s].is_sun != space.was_sun || server[s_id].zone[z].sector[s].planet != space.last_loc_planet || z != space.last_loc_zone || space.last_loc_safe )
{
draw_sector_loc ( s_id, z, s, server[s_id].zone[z].loc[temp_loc] );
space.last_loc_number = temp_loc;
space.last_loc_safe = 0;
space.last_loc_zone = z;
}
else //not required so we'll roll the dice.
{
if ( ! ( rand() % 3 ) && space.last_loc_number != temp_loc ) //1 in 3
{
draw_sector_loc ( s_id, z, s, server[s_id].zone[z].loc[temp_loc] );
space.last_loc_number = temp_loc;
space.last_loc_safe = 0;
space.last_loc_zone = z;
}
}
}
}
void add_to_sector ( char *new_user )
{
int point = 0, temp_loc;
char temp_str[1025], temp_filename[200];
struct space_user temp_usr;
SDL_Rect img_location;
SDL_Rect destination;
if ( space.at_planet && space.user_ammount >= 39 ) return; //already have max users
if ( !space.at_planet && space.user_ammount >= 40 ) return;
clear_space_user_struct ( &temp_usr );
//ship id,type,kind,class_name,user_name,user_guild
split ( temp_str, new_user, ',', &point );
temp_usr.ship_id = atoi ( temp_str );
split ( temp_str, new_user, ',', &point );
temp_usr.ship_type = atoi ( temp_str );
split ( temp_str, new_user, ',', &point );
temp_usr.ship_kind = atoi ( temp_str );
split ( temp_str, new_user, ',', &point );
temp_str[20] = '\0';
strcpy ( temp_usr.ship_name, temp_str );
split ( temp_str, new_user, ',', &point );
temp_str[20] = '\0';
strcpy ( temp_usr.username, temp_str );
split ( temp_str, new_user, ',', &point );
temp_str[20] = '\0';
strcpy ( temp_usr.guild, temp_str );
//check if field type
if ( temp_usr.ship_type == -2 )
{
temp_usr.ship_type = temp_usr.ship_kind + SHIP_MAX;
temp_usr.ship_kind = 0;
}
//check if valid
if ( temp_usr.ship_id < -1 || temp_usr.ship_id >= MAX_SERVER ) return;
if ( temp_usr.ship_type < 0 || temp_usr.ship_type >= SHIP_MAX + FIELD_TYPE_MAX ) return;
if ( temp_usr.ship_kind < 0 || temp_usr.ship_kind >= 8 ) return;
//check for special per designed "ships"
if ( temp_usr.ship_id == -1 && ( temp_usr.ship_kind >= SPECIAL_FSHIP_MAX || temp_usr.ship_kind < 0 ) ) return;
//is sos?
if ( check_sos_raw ( temp_usr.username ) > -1 )
temp_usr.sos = 1;
//give random "image"
temp_usr.image = ( rand() % 5 );
//were not destroying her yet so
temp_usr.destroy = 0;
temp_usr.hull_percent = 100;
//they aren't attacking yet...
temp_usr.attacking = -1;
temp_usr.attack_x = 0;
temp_usr.attack_y = 0;
temp_usr.attack_position = 0;
//find random place to put.
while ( 1 ) //loop until found
{
if ( space.at_planet )
temp_loc = ( rand() % 39 ) + 1;
else
temp_loc = rand() % 40;
if ( space.user[temp_loc].ship_id == -1 && !space_user_is_special ( temp_loc ) )
{
//now add this user
//stop the space_thread stuff
//SDL_LockMutex ( space_mutex );
//set this number
space.user_ammount++;
space.user[temp_loc] = temp_usr;
//draw em'
draw_space_user_ship ( temp_loc );
//put loc on backround and fresh screen
destination.x = 97;
destination.y = 65;
if ( space.visible )
{
SDL_BlitSurface ( space.temp_loc, NULL, screen, &destination );
sdl_flip_mutex();
}
//SDL_UnlockMutex ( space_mutex );
break;
}
}
}
void remove_from_sector ( char *gone_user )
{
int i;
SDL_Rect destination, user_spot;
//find this suposed user
for ( i=0;i<40;i++ )
if ( str_match ( gone_user, space.user[i].username ) )
{
//stop the space_thread stuff
//SDL_LockMutex ( space_mutex );
//stop attacking
if ( i == space.engaging ) space_disengage_user();
//well our little girlie was found, that fine little girl that she is
//now begon! you sweet thing,
clear_space_user_struct ( & ( space.user[i] ) );
//check if this user is selected remove if so
if ( i == space.user_sel )
{
space.user_sel = -1;
//and clear those little boxes like engage/chat/transfer
SDL_FillRect ( screen, &space.button[45], SDL_MapRGB ( screen->format, 0, 0, 0 ) );
SDL_FillRect ( screen, &space.button[46], SDL_MapRGB ( screen->format, 0, 0, 0 ) );
SDL_FillRect ( screen, &space.button[47], SDL_MapRGB ( screen->format, 0, 0, 0 ) );
}
//clear that bit
user_spot = space.button[i];
user_spot.x -= 97;
user_spot.y -= 65;
user_spot.w = 60;
user_spot.h = 50;
SDL_BlitSurface ( space.loc, &user_spot, space.temp_loc, &user_spot );
destination.x = 97;
destination.y = 65;
if ( space.visible )
{
SDL_BlitSurface ( space.temp_loc, NULL, screen, &destination );
sdl_flip_mutex();
}
space.user_ammount--;
if ( space.user_ammount<0 )
space.user_ammount = 0;
//SDL_UnlockMutex ( space_mutex );
}
}
void space_user_hit_us ( char *their_name )
{
//force their fire on us
//play a tune
play_sound ( sound_impact[rand() % 5] );
}
int space_user_is_special ( int u_s )
{
return ( space.user[u_s].ship_id == -1 && space.user[u_s].ship_kind > -1 && space.user[u_s].ship_kind < SPECIAL_FSHIP_MAX );
}
void space_select_user_to_scan ( int u )
{
if ( space.user[u].destroy ) return; //dont select dieing user
if ( space.user[u].ship_id != -1 || space_user_is_special ( u ) )
set_text_box_text ( NULL, &map.text_box, space.user[u].username );
}
void space_select_user ( int user_selected )
{
char hover_str[500], temp_str[21];
if ( space.user_sel == user_selected ) return;
if ( space.user[user_selected].destroy ) return; //dont select dieing user
//check if anyone is there
if ( space.user[user_selected].ship_id != -1 || space_user_is_special ( user_selected ) )
{
//check if we need to clear the redraw the newly unselected
if ( space.user_sel != -1 )
{
SDL_Rect user_spot;
//clear this area
user_spot = space.button[space.user_sel];
user_spot.x -= 97;
user_spot.y -= 65;
if ( space.visible )
SDL_BlitSurface ( space.temp_loc, &user_spot, screen, &space.button[space.user_sel] );
}
//draw in the buttons
if ( space.engaging == user_selected )
SDL_BlitSurface ( space.disengage_img, NULL, screen, &space.button[45] );
else
SDL_BlitSurface ( space.engage_img, NULL, screen, &space.button[45] );
SDL_BlitSurface ( space.chat_img, NULL, screen, &space.button[46] );
SDL_BlitSurface ( space.trade_img, NULL, screen, &space.button[47] );
space.user_sel = user_selected;
space.selection_box_i = 0;
space.transferring = 0;
//draw username if needed
if ( space.motion_sel != user_selected )
{
space.motion_sel = user_selected;
space.info_label_mode = -1;
if ( !space_user_is_special ( user_selected ) )
sprintf ( hover_str, "%s : %s %s :: %s", space.user[space.user_sel].username, space.user[space.user_sel].ship_name, ship_name ( space.user[space.user_sel].ship_kind, temp_str ), space.user[space.user_sel].guild );
else if ( space.user[space.user_sel].ship_kind == 0 || space.user[space.user_sel].ship_kind == 1 )
sprintf ( hover_str, "%s : Defense System :: %s", space.user[space.user_sel].username, space.user[space.user_sel].guild );
draw_label ( screen, hover_str, &space.info_label, 0, 230, 0 );
}
play_sound ( sound_button );
}
}
void space_engage_user()
{
SDL_Rect box_fill;
char user_attacking[24] = "9,";
char no_gun_warning[300] = "... No Weapons Equiped ..";
char in_field_warning[300] = "... Warning : Weapon Damage Effected by Sector Field ..";
if ( space.engaging >= 0 )
{
int was_engaging;
was_engaging = space.engaging;
space_disengage_user();
if ( was_engaging == space.user_sel )
return; //don't reengage...
}
//check if user has any guns at all
if ( !ship_has_weapons ( game.ship_sel ) )
{
add_chat ( 1,no_gun_warning );
return;
}
//force field?
if ( server[game.server_id].zone[game.zone].sector[game.sector].shield && !str_match ( space.user[space.user_sel].username,"Satellite" ) )
{
add_chat ( 1,in_field_warning );
}
//engage the user
space.engaging = space.user_sel;
strcat ( user_attacking,space.user[space.engaging].username );
//tell the server
send_con_server ( user_attacking );
//black out the area where the guns go
box_fill.y = 277;
box_fill.x = 215;
box_fill.w = 165;
box_fill.h = 109;
SDL_FillRect ( screen, &box_fill, SDL_MapRGB ( screen->format, 0, 0, 0 ) );
//draw in the pictures
space_draw_weapons();
//don't want this anymore
space_clear_middle_box();
//change engage to disengage
SDL_BlitSurface ( space.disengage_img, NULL, screen, &space.button[45] );
sdl_flip_mutex();
}
void space_toggle_ship_sector()
{
//toggle it
if ( space.view_sector_goods )
{
space.view_sector_goods = 0;
space.view_cargo_sector = 0;
}
else
{
space.view_sector_goods = 1;
space.view_cargo_sector = 1;
}
//draw it
if ( space.view_sector_goods )
SDL_BlitSurface ( space.viewing_sector, NULL, screen, &space.button[48] );
else
SDL_BlitSurface ( space.viewing_ship, NULL, screen, &space.button[48] );
//redraw good box?
space_draw_good_box_if_suposed_to();
sdl_flip_mutex();
}
void space_draw_gun_destroyed ( int g )
{
//got the gun?
if ( game.ship[game.ship_sel].gun[g] < 0 ) return;
if ( game.ship[game.ship_sel].gun_id[g] < 0 ) return;
if ( space.visible && !space.weapon_viewing && space.engaging > -1 )
{
rectangleRGBA ( screen, space.button[g + 53].x, space.button[g + 53].y, space.button[g + 53].x + 33, space.button[g + 53].y + 23, 255, 0 , 0, 255 );
sdl_flip_mutex();
}
}
void space_draw_weapons()
{
int i;
char temp_filename[200];
SDL_Rect destination;
destination.x = 215;
destination.y = 277;
if ( !space.weapon_viewing ) //viewing guns
{
//draw veiwing guns image
SDL_BlitSurface ( space.viewing_guns, NULL, screen, &destination );
//draw gun icons
for ( i=0;i<game.ship[game.ship_sel].gun_ammount;i++ ) //show those gun pods
if ( game.ship[game.ship_sel].gun[i] > -1 && game.ship[game.ship_sel].gun[i] < GUN_MAX && game.ship[game.ship_sel].gun_id[i] > -1 && game.ship[game.ship_sel].gun_id[i] < MAX_SERVER )
{
destination = space.button[i + 53];
destination.x++;
destination.y++;
if ( load_gun_pod_img ( i ) ) //if loaded
{
//fix a tiny bug....
if ( space.missile_firing[i] || game.ship[game.ship_sel].missile_left[i] <= 0 )
rectangleRGBA ( screen, space.button[i + 53].x, space.button[i + 53].y, space.button[i + 53].x + 33, space.button[i + 53].y + 23, 0, 0 , 0, 255 );
SDL_BlitSurface ( server[game.ship[game.ship_sel].gun_id[i]].gun[game.ship[game.ship_sel].gun[i]].gun_pod_img, NULL, screen, &destination );
}
else //if not loaded
{
SDL_BlitSurface ( game.nif_image.no_gun_pod, NULL, screen, &destination );
}
//now for the little red destroyed box
if ( game.ship[game.ship_sel].gun_destroyed[i] )
rectangleRGBA ( screen, space.button[i + 53].x, space.button[i + 53].y, space.button[i + 53].x + 33, space.button[i + 53].y + 23, 255, 0 , 0, 255 );
}
else
{
SDL_FillRect ( screen, &space.button[i + 53], SDL_MapRGB ( screen->format, 0, 0, 0 ) );
}
for ( ;i<16;i++ ) //blank out remaining spots
SDL_FillRect ( screen, &space.button[i + 53], SDL_MapRGB ( screen->format, 0, 0, 0 ) );
}
else //viewing missiles
{
//draw veiwing missiles image
SDL_BlitSurface ( space.viewing_missiles, NULL, screen, &destination );
//draw missile icons
for ( i=0;i<game.ship[game.ship_sel].missile_ammount;i++ ) //show those missile pods
if ( game.ship[game.ship_sel].missile[i] > -1 && game.ship[game.ship_sel].missile[i] < MISSILE_MAX && game.ship[game.ship_sel].missile_id[i] > -1 && game.ship[game.ship_sel].missile_id[i] < MAX_SERVER )
{
destination = space.button[i + 53];
destination.x++;
destination.y++;
if ( load_missile_pod_img ( i ) ) //if loaded
SDL_BlitSurface ( server[game.ship[game.ship_sel].missile_id[i]].missile[game.ship[game.ship_sel].missile[i]].missile_pod_img, NULL, screen, &destination );
else
SDL_BlitSurface ( game.nif_image.no_missile_pod, NULL, screen, &destination );
//draw red box around missiles with empty payloads
if ( game.ship[game.ship_sel].missile_left[i] <= 0 )
rectangleRGBA ( screen, space.button[i + 53].x, space.button[i + 53].y, space.button[i + 53].x + 33, space.button[i + 53].y + 23, 255, 0 , 0, 255 );
else if ( game.ship[game.ship_sel].gun_destroyed[i] ) //bug from hell
rectangleRGBA ( screen, space.button[i + 53].x, space.button[i + 53].y, space.button[i + 53].x + 33, space.button[i + 53].y + 23, 0, 0 , 0, 255 );
}
else
{
SDL_FillRect ( screen, &space.button[i + 53], SDL_MapRGB ( screen->format, 0, 0, 0 ) );
}
for ( ;i<16;i++ ) //blank out remaining spots
SDL_FillRect ( screen, &space.button[i + 53], SDL_MapRGB ( screen->format, 0, 0, 0 ) );
}
}
void space_disengage_user()
{
SDL_Rect box_fill, destination;
char temp_str[50], temp_filename[100], dis_code[5] = "10,";
int ship_is_there = 0;
ship_is_there = ( space.user[space.engaging].ship_id > -1 || space_user_is_special ( space.engaging ) );
//tell the server
if ( space.engaging > -1 && ship_is_there )
send_con_server ( dis_code );
//black out the area where the guns go
box_fill.y = 277;
box_fill.x = 215;
box_fill.w = 165;
box_fill.h = 107;
if ( space.visible )
SDL_FillRect ( screen, &box_fill, SDL_MapRGB ( screen->format, 0, 0, 0 ) );
//for now this is needed
space.show_ship = 1;
//draw in the pictures
//name and ship
if ( space.show_ship && space.visible )
{
sprintf ( temp_str,"User :: %s", game.username );
draw_label ( screen, temp_str, &space.user_label, 0, 240, 240 );
sprintf ( temp_str,"Guild :: %s", game.guild.name );
draw_label ( screen, temp_str, &space.guild_label, 0, 240, 240 );
destination.x = 216;
destination.y = 279;
//load image if required
if ( !server[game.ship[game.ship_sel].server_id].ship[game.ship[game.ship_sel].type].space_img[game.ship[game.ship_sel].kind] )
{
sprintf ( temp_filename, "server/%s/ships/%s/%s.jpg", server[game.server_id].servername, ship_name ( game.ship[game.ship_sel].kind, temp_str ), server[game.ship[game.ship_sel].server_id].ship[game.ship[game.ship_sel].type].name );
server[game.ship[game.ship_sel].server_id].ship[game.ship[game.ship_sel].type].space_img[game.ship[game.ship_sel].kind] = IMG_Load ( temp_filename );
}
//if image still not loaded, then load nif
if ( !server[game.ship[game.ship_sel].server_id].ship[game.ship[game.ship_sel].type].space_img[game.ship[game.ship_sel].kind] )
{
if ( !space.ship_nif_img[game.ship[game.ship_sel].kind] ) //load if required
{
sprintf ( temp_filename, "graphics/nif/nif_space_%s.jpg", ship_name ( game.ship[game.ship_sel].kind, temp_str ) );
space.ship_nif_img[game.ship[game.ship_sel].kind] = IMG_Load ( temp_filename );
}
SDL_BlitSurface ( space.ship_nif_img[game.ship[game.ship_sel].kind], NULL, screen, &destination );
}
else
{
SDL_BlitSurface ( server[game.ship[game.ship_sel].server_id].ship[game.ship[game.ship_sel].type].space_img[game.ship[game.ship_sel].kind], NULL, screen, &destination );
}
}
//redraw engage button if selecting a user otherwise blank
if ( space.engaging > -1 && ship_is_there && space.visible )
SDL_BlitSurface ( space.engage_img, NULL, screen, &space.button[45] );
//and stop the shooting
space.engaging = -1;
if ( space.visible )
sdl_flip_mutex();
}
void space_clear_middle_box()
{
space.viewing_cargo = 0;
space.show_ship = 0;
}
void space_do_show_ship()
{
SDL_Rect destination;
char temp_str[1000], temp_filename[1000];
//clear the box
space_clear_middle_box();
sprintf ( temp_str,"User :: %s", game.username );
draw_label ( screen, temp_str, &space.user_label, 0, 240, 240 );
sprintf ( temp_str,"Guild :: %s", game.guild.name );
draw_label ( screen, temp_str, &space.guild_label, 0, 240, 240 );
destination.x = 216;
destination.y = 279;
//load image if required
if ( !server[game.ship[game.ship_sel].server_id].ship[game.ship[game.ship_sel].type].space_img[game.ship[game.ship_sel].kind] )
{
sprintf ( temp_filename, "server/%s/ships/%s/%s.jpg", server[game.ship[game.ship_sel].server_id].servername, ship_name ( game.ship[game.ship_sel].kind, temp_str ), server[game.ship[game.ship_sel].server_id].ship[game.ship[game.ship_sel].type].name );
server[game.ship[game.ship_sel].server_id].ship[game.ship[game.ship_sel].type].space_img[game.ship[game.ship_sel].kind] = IMG_Load ( temp_filename );
}
//if image still not loaded, then load nif
if ( !server[game.ship[game.ship_sel].server_id].ship[game.ship[game.ship_sel].type].space_img[game.ship[game.ship_sel].kind] )
{
if ( !space.ship_nif_img[game.ship[game.ship_sel].kind] ) //load if required
{
sprintf ( temp_filename, "graphics/nif/nif_space_%s.jpg", ship_name ( game.ship[game.ship_sel].kind, temp_str ) );
space.ship_nif_img[game.ship[game.ship_sel].kind] = IMG_Load ( temp_filename );
}
SDL_BlitSurface ( space.ship_nif_img[game.ship[game.ship_sel].kind], NULL, screen, &destination );
}