00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 float SNAP_MISC_NORMYAW_OFFSET = 0;
00027
00028
00029 float SNAP_NAV_STRUCT_WALL = 40;
00030 float SNAP_NAV_STRUCT_SLOPE = 41;
00031 float SNAP_NAV_STRUCT_SLOPE_DOWN = 41.5;
00032 float SNAP_NAV_STRUCT_DOOR = 42;
00033
00034 float SNAP_NAV_DIR_FWD = 1;
00035 float SNAP_NAV_DIR_BCK = 2;
00036 float SNAP_NAV_DIR_LFT = 4;
00037 float SNAP_NAV_DIR_RGT = 8;
00038 float SNAP_NAV_DIR_UP = 16;
00039 float SNAP_NAV_DIR_DN = 32;
00040
00041 float SNAP_NAV_JMP_NRM = 1;
00042 float SNAP_NAV_JMP_RUN = 2;
00043
00044
00045
00046
00047
00048 float snap_misc_ownervisible(vector targ_origin);
00049 void snap_misc_m2o(string msg_string);
00050
00051
00052 void snap_misc_weaponswitch();
00053 void snap_misc_blockedtest();
00054 void snap_misc_blockedtest_propchg(float direction);
00055 void snap_misc_m2m(string msg_string);
00056
00057
00058 float snap_misc_normalyaw(float init_yaw);
00059 void snap_misc_showpoint(vector point, string sprite, float ttl);
00060 float snap_misc_jumptest(vector jump_origin, vector move_dir);
00061
00062
00063 void snap_misc_botspawner();
00064
00065
00066 float CountPlayers();
00067 float CountPlayersTeam(string team);
00068 float snap_misc_pickrndteam(float notmyteam);
00069 string (float teamnum) snap_misc_nameforteamnum;
00070 float snap_misc_numforteamname(string teamname);
00071 float snap_misc_bottomforteamnum(float teamnum);
00072 float snap_misc_topforteamnum(float teamnum);
00073
00074
00075
00076
00077
00079
00089 float snap_misc_ownervisible(vector targ_origin)
00090 {
00091 traceline(self.owner.origin, targ_origin, true, self);
00092
00093 if( trace_fraction == 1 )
00094 {
00095 local float obj_orig_yaw, player_normal_yaw;
00096 local float min_fov_yaw, max_fov_yaw;
00097
00098
00099 obj_orig_yaw = vectoyaw(targ_origin - self.owner.origin);
00100 obj_orig_yaw = snap_misc_normalyaw(obj_orig_yaw);
00101
00102
00103 player_normal_yaw = snap_misc_normalyaw(self.owner.angles_y);
00104
00105
00106
00107
00108
00109 min_fov_yaw = player_normal_yaw - 45;
00110
00111
00112
00113
00114
00115
00116 max_fov_yaw = player_normal_yaw + 45;
00117
00118
00119
00120
00121
00122
00123 if( min_fov_yaw <= obj_orig_yaw && max_fov_yaw >= obj_orig_yaw )
00124 {
00125 return true;
00126 }
00127 else
00128 {
00129
00130 obj_orig_yaw = obj_orig_yaw - 360;
00131 if( min_fov_yaw <= obj_orig_yaw && max_fov_yaw >= obj_orig_yaw )
00132 {
00133 return true;
00134 }
00135 else
00136 {
00137 return false;
00138 }
00139 }
00140 }
00141 else
00142 {
00143 return false;
00144 }
00145 };
00146
00155 void snap_misc_m2o(string msg_string)
00156 {
00157 if( ! self.owner.agrip_aux.state )
00158 sprint(self.owner, PRINT_MEDIUM, "!", msg_string);
00159 else
00160 sprint(self.owner, PRINT_MEDIUM, msg_string);
00161 };
00162
00163
00164
00166
00172 void snap_misc_weaponswitch()
00173 {
00174 if( self.weapon == IT_AXE )
00175 snap_misc_m2m("Axe.\n");
00176 else if( self.weapon == IT_SHOTGUN )
00177 snap_misc_m2m("Shotgun.\n");
00178 else if( self.weapon == IT_SUPER_SHOTGUN )
00179 snap_misc_m2m("Double-Barrelled Shotgun.\n");
00180 else if (self.weapon == IT_NAILGUN )
00181 snap_misc_m2m("Nailgun.\n");
00182 else if (self.weapon == IT_SUPER_NAILGUN )
00183 snap_misc_m2m("Super Nailgun.\n");
00184 else if (self.weapon == IT_GRENADE_LAUNCHER )
00185 snap_misc_m2m("Grenade Launcher.\n");
00186 else if (self.weapon == IT_ROCKET_LAUNCHER )
00187 snap_misc_m2m("Rocket Launcher.\n");
00188 else if (self.weapon == IT_LIGHTNING )
00189 snap_misc_m2m("Lightning Gun.\n");
00190 };
00191
00207 void snap_misc_blockedtest()
00208 {
00209
00210 makevectors(self.angles);
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221 tracebox(self.origin, VEC_HULL_MIN, VEC_HULL_MAX, (self.origin + ( v_forward * 10 ) ), true, self);
00222 snap_misc_blockedtest_propchg(SNAP_NAV_DIR_FWD);
00223
00224
00225 tracebox(self.origin, VEC_HULL_MIN, VEC_HULL_MAX, (self.origin - ( v_forward * 10 ) ), true, self);
00226 snap_misc_blockedtest_propchg(SNAP_NAV_DIR_BCK);
00227
00228
00229 tracebox(self.origin, VEC_HULL_MIN, VEC_HULL_MAX, (self.origin - ( v_right * 10 ) ), true, self);
00230 snap_misc_blockedtest_propchg(SNAP_NAV_DIR_LFT);
00231
00232
00233 tracebox(self.origin, VEC_HULL_MIN, VEC_HULL_MAX, (self.origin + ( v_right * 10 ) ), true, self);
00234 snap_misc_blockedtest_propchg(SNAP_NAV_DIR_RGT);
00235
00236
00237
00238 if( 0 )
00239 {
00240
00241 tracebox(self.origin, VEC_HULL_MIN, VEC_HULL_MAX, (self.origin + ( v_up * 10 ) ), true, self);
00242 snap_misc_blockedtest_propchg(SNAP_NAV_DIR_UP);
00243
00244
00245 tracebox(self.origin, VEC_HULL_MIN, VEC_HULL_MAX, (self.origin - ( v_up * 10 ) ), true, self);
00246 snap_misc_blockedtest_propchg(SNAP_NAV_DIR_DN);
00247 }
00248 };
00249
00250
00251
00252
00253
00254
00255
00256
00257 void snap_misc_blockedtest_propchg(float direction)
00258 {
00259
00260
00261
00262
00263
00264
00265
00266
00267 if( trace_fraction == 0 )
00268 {
00269
00270
00271
00272
00273 if( ! (self.agrip_aux.ammo_nails & direction) )
00274 {
00275
00276 self.agrip_aux.ammo_shells = self.agrip_aux.ammo_shells + direction;
00277 self.agrip_aux.ammo_nails = self.agrip_aux.ammo_nails + direction;
00278
00279
00280 self.agrip_aux.ammo_rockets = self.agrip_aux.ammo_rockets + 1;
00281 }
00282 }
00283 else
00284 {
00285
00286 if( (self.agrip_aux.ammo_nails & direction)
00287 || (self.agrip_aux.ammo_shells & direction) )
00288 {
00289
00290 self.agrip_aux.ammo_shells = self.agrip_aux.ammo_shells - ( self.agrip_aux.ammo_shells & direction );
00291 self.agrip_aux.ammo_nails = self.agrip_aux.ammo_nails - ( self.agrip_aux.ammo_nails & direction );
00292
00293
00294 self.agrip_aux.ammo_rockets = self.agrip_aux.ammo_rockets - 1;
00295 }
00296 }
00297 };
00298
00307 void snap_misc_m2m(string msg_string)
00308 {
00309 if( ! self.agrip_aux.state )
00310 sprint(self, PRINT_MEDIUM, "!", msg_string);
00311 else
00312 sprint(self, PRINT_MEDIUM, msg_string);
00313 };
00314
00315
00316
00318
00331 float snap_misc_normalyaw(float init_yaw)
00332 {
00333 local float normal_yaw;
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343 normal_yaw = init_yaw - SNAP_MISC_NORMYAW_OFFSET;
00344
00345
00346 if( normal_yaw <= 0 )
00347 normal_yaw = normal_yaw + 360;
00348 else if( normal_yaw > 360 )
00349 normal_yaw = normal_yaw - 360;
00350
00351
00352 normal_yaw = 360 - normal_yaw;
00353
00354
00355
00356
00357
00358
00359
00360
00361 return normal_yaw;
00362 };
00363
00372 void snap_misc_showpoint(vector point, string sprite, float ttl)
00373 {
00374 local entity temp_point_ent;
00375 temp_point_ent = spawn();
00376 setorigin(temp_point_ent, point);
00377 setmodel(temp_point_ent, sprite);
00378
00379 temp_point_ent.think = SUB_Remove;
00380 temp_point_ent.nextthink = time + ttl;
00381 };
00382
00392 float snap_misc_jumptest(vector jump_origin, vector move_dir)
00393 {
00394 local float retval;
00395 local vector jumptestpoint;
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406 jumptestpoint = jump_origin + move_dir * 240;
00407
00408
00409
00410 traceline(jumptestpoint, jumptestpoint - '0 0 100', true, self);
00411
00412 if( trace_fraction != 1 )
00413 {
00414
00415 retval = SNAP_NAV_JMP_RUN;
00416 }
00417
00418
00419
00420 jumptestpoint = jump_origin + move_dir * 110;
00421
00422
00423
00424 traceline(jumptestpoint, jumptestpoint - '0 0 100', true, self);
00425
00426 if( trace_fraction != 1 )
00427 {
00428
00429 retval = SNAP_NAV_JMP_NRM;
00430 }
00431
00432 return retval;
00433 };
00434
00435
00436
00438
00461 void snap_misc_botspawner()
00462 {
00463 local string tteam;
00464 local float tbot, ttop;
00465
00466 if( self.state == 0 )
00467 {
00468 if( self.items > 0 )
00469 {
00470
00471 if( self.lip < self.frags )
00472 {
00473
00474 if( teamplay )
00475 {
00476
00477 tteam = infokey(world, "ag_team1name");
00478 tbot = snap_misc_bottomforteamnum(1);
00479 ttop = snap_misc_topforteamnum(1);
00480 create_bot(tbot, ttop, tteam, false);
00481 }
00482 else
00483 {
00484
00485
00486
00487 tteam = "n/a";
00488 create_bot(0, 12, tteam, false);
00489 }
00490 self.lip = self.lip + 1;
00491 }
00492 else
00493 {
00494 self.lip = 0;
00495 self.state = 1;
00496 }
00497 }
00498 else
00499 {
00500 self.state = 1;
00501 }
00502 self.nextthink = time + 1;
00503 }
00504 else if( self.state == 1 )
00505 {
00506 if( self.items > 1 )
00507 {
00508
00509 if( self.lip < self.frags )
00510 {
00511
00512 tteam = infokey(world, "ag_team2name");
00513 tbot = snap_misc_bottomforteamnum(2);
00514 ttop = snap_misc_topforteamnum(2);
00515 create_bot(tbot, ttop, tteam, false);
00516 self.lip = self.lip + 1;
00517 }
00518 else
00519 {
00520 self.lip = 0;
00521 self.state = 2;
00522 }
00523 }
00524 else
00525 {
00526 self.state = 2;
00527 }
00528 self.nextthink = time + 1;
00529 }
00530 else if( self.state == 2 )
00531 {
00532 if( self.items > 2 )
00533 {
00534
00535 if( self.lip < self.frags )
00536 {
00537
00538 tteam = infokey(world, "ag_team3name");
00539 tbot = snap_misc_bottomforteamnum(3);
00540 ttop = snap_misc_topforteamnum(3);
00541 create_bot(tbot, ttop, tteam, false);
00542 self.lip = self.lip + 1;
00543 }
00544 else
00545 {
00546 self.lip = 0;
00547 self.state = 3;
00548 }
00549 }
00550 else
00551 {
00552 self.state = 3;
00553 }
00554 self.nextthink = time + 1;
00555 }
00556 else if( self.state == 3 )
00557 {
00558 if( self.items > 3 )
00559 {
00560
00561 if( self.lip < self.frags )
00562 {
00563
00564 tteam = infokey(world, "ag_team4name");
00565 tbot = snap_misc_bottomforteamnum(4);
00566 ttop = snap_misc_topforteamnum(4);
00567 create_bot(tbot, ttop, tteam, false);
00568 self.lip = self.lip + 1;
00569 }
00570 else
00571 {
00572
00573 self.state = 4;
00574 }
00575 }
00576 else
00577 {
00578 self.state = 4;
00579 }
00580 self.nextthink = time + 1;
00581 }
00582 else
00583 {
00584
00585
00586 remove(self);
00587 }
00588 }
00589
00590
00591
00593
00594
00595
00596 float CountPlayers()
00597 {
00598 local entity plr;
00599 local float count;
00600
00601 plr = find(world, classname, "player");
00602 while( plr != world )
00603 {
00604 if( plr.netname != "" )
00605 count = count + 1;
00606
00607 plr = find(plr, classname, "player");
00608 }
00609
00610 return count;
00611 }
00612
00613
00614
00615
00616 float CountPlayersTeam(string team)
00617 {
00618 local entity plr;
00619 local float count;
00620
00621 plr = find(world, classname, "player");
00622 while( plr != world )
00623 {
00624 if( plr.netname != "" )
00625 if( infokey(plr, "team") == team )
00626 count = count + 1;
00627
00628 plr = find(plr, classname, "player");
00629 }
00630
00631 return count;
00632 }
00633
00645 float snap_misc_pickrndteam(float notmyteam)
00646 {
00647 local float numteams;
00648 local float rnd;
00649 local float okteam;
00650
00651
00652
00653 numteams = stof(infokey(world, "ag_numteams"));
00654
00655 if( notmyteam )
00656 {
00657 local float myteam;
00658 myteam = snap_misc_numforteamname(infokey(self, "team"));
00659
00660
00661
00662 }
00663
00664 okteam = 0;
00665 while( !okteam )
00666 {
00667 rnd = 1 + ( random() * ( numteams - 1 ) );
00668 rnd = rint(rnd);
00669
00670
00671
00672
00673 if( notmyteam )
00674 {
00675 if( rnd == myteam )
00676 {
00677
00678 okteam = 0;
00679 }
00680 else
00681 {
00682
00683 okteam = 1;
00684 }
00685 }
00686 else
00687 {
00688
00689 okteam = 1;
00690 }
00691 }
00692
00693 return rnd;
00694 }
00695
00703 string (float teamnum) snap_misc_nameforteamnum =
00704 {
00705 if( teamnum == 1 )
00706 return infokey(world, "ag_team1name");
00707 else if( teamnum == 2 )
00708 return infokey(world, "ag_team2name");
00709 else if( teamnum == 3 )
00710 return infokey(world, "ag_team3name");
00711 else if( teamnum == 4 )
00712 return infokey(world, "ag_team4name");
00713 else
00714 {
00715 dprint("ERROR: Invalid team number ", ftos(teamnum), "!\n");
00716 error("snap_misc_nameforteamnum called with invalid team number!\n");
00717 }
00718 }
00719
00730 float snap_misc_numforteamname(string teamname)
00731 {
00732 local string s_teamname;
00733 local float retval;
00734
00735
00736 s_teamname = strzone(teamname);
00737
00738
00739 if ( s_teamname == infokey(world, "ag_team1name") )
00740 retval = 1;
00741 else if ( s_teamname == infokey(world, "ag_team2name") )
00742 retval = 2;
00743 else if ( s_teamname == infokey(world, "ag_team3name") )
00744 retval = 3;
00745 else if ( s_teamname == infokey(world, "ag_team4name") )
00746 retval = 4;
00747 else
00748 retval = 0;
00749
00750
00751 strunzone(s_teamname);
00752
00753 return retval;
00754 }
00755
00763 float snap_misc_bottomforteamnum(float teamnum)
00764 {
00765 if( teamnum == 1 )
00766 return 4;
00767 else if( teamnum == 2 )
00768 return 13;
00769 else if( teamnum == 3 )
00770 return 12;
00771 else if (teamnum == 4 )
00772 return 3;
00773 else
00774 {
00775 dprint("ERROR: Invalid team number ", ftos(teamnum), "!\n");
00776 error("snap_misc_bottomforteamnum called with invalid team number!\n");
00777 }
00778 }
00779
00787 float snap_misc_topforteamnum(float teamnum)
00788 {
00789 if( teamnum == 1 )
00790 return 0;
00791 else if( teamnum == 2 )
00792 return 0;
00793 else if( teamnum == 3 )
00794 return 0;
00795 else if( teamnum == 4 )
00796 return 0;
00797 else
00798 {
00799 dprint("ERROR: Invalid team number ", ftos(teamnum), "!\n");
00800 error("snap_misc_bottomforteamnum called with invalid team number!\n");
00801 }
00802 }
00803
00804