void fire_fly() { gedict_t *fireball; fireball = spawn(); fireball->s.v.solid = SOLID_TRIGGER; fireball->s.v.movetype = MOVETYPE_TOSS; fireball->isMissile = true; // well, you can really treat fireball as missilie, nothing bad gonna heppen. SetVector( fireball->s.v.velocity, ( g_random() * 100 ) - 50, ( g_random() * 100 ) - 50, self->speed + ( g_random() * 200 ) ); fireball->classname = "fireball"; setmodel( fireball, "progs/lavaball.mdl" ); setsize( fireball, 0, 0, 0, 0, 0, 0 ); setorigin( fireball, PASSVEC3( self->s.v.origin ) ); fireball->s.v.nextthink = g_globalvars.time + 5; fireball->think = ( func_t ) SUB_Remove; fireball->touch = ( func_t ) fire_touch; self->s.v.nextthink = g_globalvars.time + ( g_random() * 5 ) + 3; self->think = ( func_t ) fire_fly; }
void BotEvadeLogic(gedict_t* self) { gedict_t* enemy_ = &g_edicts[self->s.v.enemy]; self->fb.bot_evade = false; if (deathmatch <= 3 && !isRA()) { if (isDuel() && g_random() < CHANCE_EVADE_DUEL) { if ((self->s.v.origin[2] + 18) > (enemy_->s.v.absmin[2] + enemy_->s.v.view_ofs[2])) { if ((int)self->s.v.items & IT_ROCKET_LAUNCHER && self->s.v.ammo_rockets > 4) { if (!self->s.v.waterlevel) { self->fb.bot_evade = (qbool) (self->s.v.health > 70) && (self->s.v.armorvalue > 100) && !self->fb.enemy_visible; } } } } else if (! isDuel() && g_random() < CHANCE_EVADE_NONDUEL) { if ((self->s.v.origin[2] + 18) > (enemy_->s.v.absmin[2] + enemy_->s.v.view_ofs[2])) { if (((int)self->s.v.items & IT_ROCKET_LAUNCHER) || ((int)self->s.v.items & IT_LIGHTNING)) { if ((self->s.v.ammo_cells >= 20) || (self->s.v.ammo_rockets > 3)) { if (!self->s.v.waterlevel) { if ((self->s.v.health > 70) && (self->s.v.armorvalue > 90)) { self->fb.bot_evade = (qbool) (!((int)self->s.v.items & (IT_INVULNERABILITY | IT_INVISIBILITY | IT_QUAD))); } } } } } } } }
void fire_fly( ) { gedict_t *fireball; fireball = spawn( ); newmis = fireball; g_globalvars.newmis = EDICT_TO_PROG( newmis ); fireball->s.v.solid = SOLID_TRIGGER; fireball->s.v.movetype = MOVETYPE_TOSS; SetVector( fireball->s.v.velocity, ( g_random( ) * 100 ) - 50, ( g_random( ) * 100 ) - 50, self->speed + ( g_random( ) * 200 ) ); fireball->s.v.classname = "fireball"; setmodel( fireball, "progs/lavaball.mdl" ); setsize( fireball, 0, 0, 0, 0, 0, 0 ); setorigin( fireball, PASSVEC3( self->s.v.origin ) ); fireball->s.v.nextthink = g_globalvars.time + 5; fireball->s.v.think = ( func_t ) SUB_Remove; fireball->s.v.touch = ( func_t ) fire_touch; self->s.v.nextthink = g_globalvars.time + ( g_random( ) * 5 ) + 3; self->s.v.think = ( func_t ) fire_fly; }
void DropRing( float timeleft ) { gedict_t *item; item = spawn(); VectorCopy( self->s.v.origin, item->s.v.origin ); //item.origin = self.origin; item->s.v.velocity[2] = 300; item->s.v.velocity[0] = -100 + ( g_random() * 200 ); item->s.v.velocity[1] = -100 + ( g_random() * 200 ); item->s.v.flags = FL_ITEM; item->s.v.solid = SOLID_TRIGGER; item->s.v.movetype = MOVETYPE_TOSS; item->s.v.noise = "items/inv1.wav"; setmodel( item, "progs/invisibl.mdl" ); setsize( item, -16, -16, -24, 16, 16, 32 ); item->cnt = g_globalvars.time + timeleft; item->s.v.touch = ( func_t ) r_touch; item->s.v.nextthink = g_globalvars.time + timeleft; // remove after 30 seconds item->s.v.think = ( func_t ) SUB_Remove; }
void tdeath_touch( ) { // gedict_t *spot; if ( other == PROG_TO_EDICT( self->s.v.owner ) ) return; if ( streq( other->s.v.classname, "player" ) ) { if ( other->invincible_finished > g_globalvars.time ) { self->s.v.classname = "teledeath2"; } if ( strneq( PROG_TO_EDICT( self->s.v.owner )->s.v.classname, "player" ) ) { T_Damage( PROG_TO_EDICT( self->s.v.owner ), self, self, 5000 ); return; } } if ( other->s.v.health ) { T_Damage( other, self, self, 5000 ); } if ( other->s.v.think == ( func_t ) TeamFortress_DetpackExplode ) { other->s.v.solid = SOLID_NOT; other->s.v.nextthink = g_globalvars.time + 1 + g_random( ) * 2; dremove( other->oldenemy ); G_bprint( 1, "%s's detpack was telefragged by %s\n", other->real_owner->s.v.netname, PROG_TO_EDICT( self->s.v.owner )->s.v.netname ); } }
void make_bubbles( ) { spawn_buble( self ); self->s.v.nextthink = g_globalvars.time + g_random( ) + 0.5; self->s.v.think = ( func_t ) make_bubbles; }
// created this function because it is called from client.qc as well // was originally part of PlayerDie() and hasn't been altered void StartDie () { if ( self->s.v.weapon == IT_AXE ) { player_die_ax1(); return; } // if ( k_yawnmode ) // qqshka: this way it better if ( 1 ) { // Yawnmode: exclude diea1 and diec1 so the respawn time is always 900 ms switch( i_rnd(1, 3) ) { case 1: player_dieb1(); break; case 2: player_died1(); break; default: player_diee1(); break; } } else { // Note that this generates random values in 1..6 range, so player_diee1 is // executed twice as often as other death sequences. Dunno if this should be fixed -- Tonik int i = 1 + floor( g_random() * 6 ); switch( i ) { case 1: player_diea1(); break; case 2: player_dieb1(); break; case 3: player_diec1(); break; case 4: player_died1(); break; default: player_diee1(); break; } } }
int TeamFortress_TeamPutPlayerInTeam( ) { int i, j, lowest, likely_team; likely_team = (int)( g_random( ) * number_of_teams ) + 1; if ( !likely_team ) likely_team = number_of_teams; lowest = 33; for ( i = 1; i < number_of_teams + 1; i++ ) { j = TeamFortress_TeamGetNoPlayers( i ); if ( j < lowest ) { if ( TeamFortress_TeamGetMaxPlayers( i ) > j ) { lowest = j; likely_team = i; } } } return TeamFortress_TeamSet( likely_team ); }
int Sentry_FindTarget_Angel( ) { gedict_t *client; gedict_t *enemy = PROG_TO_EDICT( self->s.v.enemy ); if ( enemy != world ) { if ( CheckTarget( enemy ) ) { if ( g_globalvars.time > self->height ) { Sentry_FoundTarget( ); return 1; } else return 0; } } for ( client = world; (client = trap_find( client, FOFS( s.v.classname ), "player" )); ) { if ( CheckTarget( client ) ) { self->s.v.enemy = EDICT_TO_PROG( client ); self->height = g_globalvars.time + 0.1 * ( int ) ( g_random( ) * tfset_sgppl ); // self.height = g_globalvars.time + 0.1 * Q_rint(sgppl); if ( self->height == g_globalvars.time ) { Sentry_FoundTarget( ); return 1; } return 0; } } self->s.v.enemy = EDICT_TO_PROG( world ); return 0; }
void _ogre_stand5( void ) { if ( g_random() < 0.2 ) sound( self, CHAN_VOICE, "ogre/ogidle.wav", 1, ATTN_IDLE ); ai_stand(); }
int add_xauth_cookie(int display, const char *file) { FILE *dp; char cookie_str[33]; char cookie_bin[16]; char xauth_str[256]; int ret; g_random(cookie_bin, 16); g_bytes_to_hexstr(cookie_bin, 16, cookie_str, 33); g_sprintf(xauth_str, "xauth -q -f %s add :%d . %s", file, display, cookie_str); dp = popen(xauth_str, "r"); if (dp == NULL) { log_message(LOG_LEVEL_ERROR, "Unable to launch xauth"); return 1; } ret = pclose(dp); if (ret < 0) { log_message(LOG_LEVEL_ERROR, "An error occurred while running xauth"); return 1; } return 0; }
void DeathSound() { int rs; // water death sounds if ( self->s.v.waterlevel == 3 ) { DeathBubbles( 5 ); sound( self, CHAN_VOICE, "player/h2odeath.wav", 1, ATTN_NONE ); return; } rs = ( ( g_random() * 4 ) + 1 ); if ( rs == 1 ) self->noise = "player/death1.wav"; if ( rs == 2 ) self->noise = "player/death2.wav"; if ( rs == 3 ) self->noise = "player/death3.wav"; if ( rs == 4 ) self->noise = "player/death4.wav"; if ( rs == 5 ) self->noise = "player/death5.wav"; sound( self, CHAN_VOICE, self->noise, 1, ATTN_NONE ); return; }
/* ================ SpawnMeatSpray ================ */ void SpawnMeatSpray( vec3_t org, vec3_t vel ) { gedict_t *missile; //vec3_t org; missile = spawn(); missile->s.v.owner = EDICT_TO_PROG( self ); missile->s.v.movetype = MOVETYPE_BOUNCE; missile->s.v.solid = SOLID_NOT; makevectors( self->s.v.angles ); VectorCopy( vel, missile->s.v.velocity ); // missile->s.v.velocity = vel; missile->s.v.velocity[2] = missile->s.v.velocity[2] + 250 + 50 * g_random(); SetVector( missile->s.v.avelocity, 3000, 1000, 2000 ); // missile.avelocity = '3000 1000 2000'; // set missile duration missile->s.v.nextthink = g_globalvars.time + 1; missile->s.v.think = ( func_t ) SUB_Remove; setmodel( missile, "progs/zom_gib.mdl" ); setsize( missile, 0, 0, 0, 0, 0, 0 ); setorigin( missile, PASSVEC3( org ) ); }
// !!! do not confuse rpickup and pickup void vote_check_rpickup () { float frnd; int i, tn, pl_cnt, pl_idx; gedict_t *p; int veto; if ( match_in_progress || k_captains ) return; if ( !get_votes( OV_RPICKUP ) ) return; // Firstly obtain the number of players we have in total on server pl_cnt = CountPlayers(); if ( pl_cnt < 4 ) return; veto = is_admins_vote( OV_RPICKUP ); if( veto || !get_votes_req( OV_RPICKUP, true ) ) { vote_clear( OV_RPICKUP ); for( p = world; (p = find_plr( p )); ) p->k_teamnumber = 0; for( tn = 1; pl_cnt > 0; pl_cnt-- ) { frnd = g_random(); // bound is macros - so u _can't_ put g_random inside bound pl_idx = bound(0, (int)( frnd * pl_cnt ), pl_cnt-1 ); // select random player between 0 and pl_cnt for( i = 0, p = world; (p = find_plr( p )); ) { if ( p->k_teamnumber ) continue; if ( i == pl_idx ) { p->k_teamnumber = tn; tn = (tn == 1 ? 2 : 1); // next random player will be in other team if( p->k_teamnumber == 1 ) stuffcmd_flags(p, STUFFCMD_IGNOREINDEMO, "break\ncolor 4\nskin \"\"\nteam red\n"); else stuffcmd_flags(p, STUFFCMD_IGNOREINDEMO, "break\ncolor 13\nskin \"\"\nteam blue\n"); break; } i++; } } if ( veto ) G_bprint(2, "console: admin veto for %s\n", redtext("random pickup")); else G_bprint(2, "console: %s game it is then\n", redtext("random pickup")); return; } }
static void SetNextThinkTime(gedict_t* ent) { if (!((int)ent->s.v.flags & FL_ONGROUND)) { ent->fb.frogbot_nextthink += 0.15 + (0.015 * g_random ()); if (PAST (frogbot_nextthink)) { ent->fb.frogbot_nextthink = g_globalvars.time + 0.16; } } }
/* ============= ai_melee ============= */ void ai_melee() { vec3_t delta; float ldmg; if ( !self->s.v.enemy ) return; // removed before stroke VectorSubtract( PROG_TO_EDICT( self->s.v.enemy )->s.v.origin, self->s.v.origin, delta ); if ( vlen( delta ) > 60 ) return; ldmg = ( g_random() + g_random() + g_random() ) * 3; PROG_TO_EDICT( self->s.v.enemy )->deathtype = dtSQUISH; // FIXME T_Damage( PROG_TO_EDICT( self->s.v.enemy ), self, self, ldmg ); }
void VelocityForDamage( float dm, vec3_t v ) { vec3_t v2; if ( vlen( damage_inflictor->s.v.velocity ) > 0 ) { VectorScale( damage_inflictor->s.v.velocity, 0.5, v ); VectorSubtract( self->s.v.origin, damage_inflictor->s.v.origin, v2 ); VectorNormalize( v2 ); VectorScale( v2, 25, v2 ); VectorAdd( v, v2, v ); // v = 0.5 * damage_inflictor->s.v.velocity; // v = v + (25 * normalize((self->s.v.origin)-damage_inflictor->s.v.origin)); v[2] = 100 + 240 * g_random(); v[0] = v[0] + ( 200 * crandom() ); v[1] = v[1] + ( 200 * crandom() ); //dprint ("Velocity gib\n"); } else { v[0] = 100 * crandom(); v[1] = 100 * crandom(); v[2] = 200 + 100 * g_random(); } //v[0] = 100 * crandom(); //v[1] = 100 * crandom(); //v[2] = 200 + 100 * g_random(); if ( dm > -50 ) { // dprint ("level 1\n"); VectorScale( v, 0.7, v ); // v = v * 0.7; } else if ( dm > -200 ) { // dprint ("level 3\n"); VectorScale( v, 2, v ); // v = v * 2; } else VectorScale( v, 10, v ); // v = v * 10; return; //v; }
// Called when the bot has a touch marker set static void BotTouchMarkerLogic() { TargetEnemyLogic(self); if (PAST(goal_refresh_time)) { UpdateGoal(self); } if (self->fb.path_state & BOTPATH_RJ_IN_PROGRESS) { if (self->s.v.velocity[2] <= 0) { self->fb.path_state &= ~BOTPATH_RJ_IN_PROGRESS; } } if (! (self->fb.path_state & BOTPATH_RJ_IN_PROGRESS)) { if (PAST (linked_marker_time)) { self->fb.old_linked_marker = NULL; } if (self->fb.old_linked_marker != self->fb.touch_marker) { ProcessNewLinkedMarker (self); } } if (FUTURE(arrow_time)) { if (self->isBot && self->fb.debug_path) { G_bprint(PRINT_HIGH, "%3.2f: arrow_time is %3.2f\n", g_globalvars.time, self->fb.arrow_time); } if (FUTURE(arrow_time2)) { if (g_random() < 0.5) { SetLinkedMarker (self, self->fb.touch_marker, "BotTouchMarkerLogic"); self->fb.old_linked_marker = self->fb.linked_marker; self->fb.path_state = 0; self->fb.linked_marker_time = g_globalvars.time + 0.3; } } } else if (self->fb.linked_marker) { vec3_t dir_move; BotMoveTowardsLinkedMarker(self, dir_move); BotOnGroundMovement(self, dir_move); SetDirectionMove (self, dir_move, ((int)self->s.v.flags & FL_ONGROUND) ? "OnGround" : "InAir"); } else { // The map is, imo, broken at this point, but some old fbca maps are missing links // and at this point would use 'world' // Deliberately don't move and hope that the fall gets us somewhere vec3_t dir_move = { 0, 0, 0 }; SetDirectionMove(self, dir_move, "NoLinkedMarker!"); } SelectWeapon(); }
void SP_misc_fireball() { trap_precache_model( "progs/lavaball.mdl" ); self->classname = "fireball"; self->s.v.nextthink = g_globalvars.time + ( g_random() * 5 ); self->think = ( func_t ) fire_fly; if ( !self->speed ) self->speed = 1000; }
int i_rnd( int from, int to ) { float r; if ( from >= to ) return from; r = (int)(from + (1.0 + to - from) * g_random()); return bound(from, r, to); }
// Shell Eject void ShellHit ( ) { if ( self->s.v.skin == 1 ) sound( self, 3, "weapons/shell2.wav", 0.5, 1 ); else { if ( g_random( ) < 0.5 ) sound( self, 3, "weapons/tink1.wav", 0.5, 1 ); else sound( self, 3, "weapons/tink2.wav", 0.6, 1 ); } return; }
static void BotDodgeMovement(gedict_t* self, vec3_t dir_move, float dodge_factor) { if (dodge_factor) { if (dodge_factor < 0) { ++dodge_factor; } else { --dodge_factor; } trap_makevectors(self->s.v.v_angle); VectorMA(dir_move, g_random() * self->fb.skill.dodge_amount * dodge_factor, g_globalvars.v_right, dir_move); } }
void bubble_bob( ) { float rnd1, rnd2, rnd3; //vec3_t vtmp1, modi; self->cnt = self->cnt + 1; if ( self->cnt == 4 ) bubble_split( ); if ( self->cnt == 20 ) ent_remove( self ); rnd1 = self->s.v.velocity[0] + ( -10 + ( g_random( ) * 20 ) ); rnd2 = self->s.v.velocity[1] + ( -10 + ( g_random( ) * 20 ) ); rnd3 = self->s.v.velocity[2] + 10 + g_random( ) * 10; if ( rnd1 > 10 ) rnd1 = 5; if ( rnd1 < -10 ) rnd1 = -5; if ( rnd2 > 10 ) rnd2 = 5; if ( rnd2 < -10 ) rnd2 = -5; if ( rnd3 < 10 ) rnd3 = 15; if ( rnd3 > 30 ) rnd3 = 25; self->s.v.velocity[0] = rnd1; self->s.v.velocity[1] = rnd2; self->s.v.velocity[2] = rnd3; self->s.v.nextthink = g_globalvars.time + 0.5; self->s.v.think = ( func_t ) bubble_bob; }
void make_explosion ( ) { newmis = spawn ( ); setmodel( newmis, "progs/s_expl.spr" ); setorigin( newmis, PASSVEC3( self->s.v.origin ) ); newmis->s.v.movetype = 8; newmis->s.v.solid = SOLID_NOT; sound ( newmis, 0, "weapons/flmfire2.wav", 1, 1 ); newmis->s.v.effects = 8; newmis->s.v.velocity[2] = ( g_random () * 250.000000 ); newmis->s.v.nextthink = g_globalvars.time + 0.05; newmis->s.v.think = ( func_t ) s2_explode1; newmis->s.v.nextthink = g_globalvars.time + 0.05; }
void SP_misc_fireball( ) { if ( !CheckExistence( ) ) { dremove( self ); return; } trap_precache_model( "progs/lavaball.mdl" ); self->s.v.classname = "fireball"; self->s.v.nextthink = g_globalvars.time + ( g_random( ) * 5 ); self->s.v.think = ( func_t ) fire_fly; if ( !self->speed ) self->speed = 1000; }
void DropQuad( float timeleft ) { gedict_t *item; item = spawn(); VectorCopy( self->s.v.origin, item->s.v.origin ); item->s.v.velocity[2] = 300; item->s.v.velocity[0] = -100 + ( g_random() * 200 ); item->s.v.velocity[1] = -100 + ( g_random() * 200 ); item->s.v.flags = FL_ITEM; item->s.v.solid = SOLID_TRIGGER; item->s.v.movetype = MOVETYPE_TOSS; item->s.v.noise = "items/damage.wav"; setmodel( item, "progs/quaddama.mdl" ); setsize( item, -16, -16, -24, 16, 16, 32 ); item->cnt = g_globalvars.time + timeleft; item->s.v.touch = ( func_t ) q_touch; item->s.v.nextthink = g_globalvars.time + timeleft; // remove it with the time left on it item->s.v.think = ( func_t ) SUB_Remove; }
gedict_t *ThrowGib( char *gibname, float dm ) { gedict_t *newent; int k_short_gib = cvar( "k_short_gib" ); // if set - remove faster newent = spawn(); VectorCopy( self->s.v.origin, newent->s.v.origin ); setmodel( newent, gibname ); setsize( newent, 0, 0, 0, 0, 0, 0 ); VelocityForDamage( dm, newent->s.v.velocity ); newent->s.v.movetype = MOVETYPE_BOUNCE; newent->isMissile = true; newent->s.v.solid = SOLID_NOT; newent->s.v.avelocity[0] = g_random() * 600; newent->s.v.avelocity[1] = g_random() * 600; newent->s.v.avelocity[2] = g_random() * 600; newent->think = ( func_t ) SUB_Remove; newent->s.v.ltime = g_globalvars.time; newent->s.v.nextthink = g_globalvars.time + ( k_short_gib ? 2 : ( 10 + g_random() * 10 ) ); newent->s.v.frame = 0; newent->s.v.flags = 0; return newent; }
void SP_misc_noisemaker() { trap_precache_sound( "enforcer/enfire.wav" ); trap_precache_sound( "enforcer/enfstop.wav" ); trap_precache_sound( "enforcer/sight1.wav" ); trap_precache_sound( "enforcer/sight2.wav" ); trap_precache_sound( "enforcer/sight3.wav" ); trap_precache_sound( "enforcer/sight4.wav" ); trap_precache_sound( "enforcer/pain1.wav" ); trap_precache_sound( "enforcer/pain2.wav" ); trap_precache_sound( "enforcer/death1.wav" ); trap_precache_sound( "enforcer/idle1.wav" ); self->s.v.nextthink = g_globalvars.time + 0.1 + g_random(); self->think = ( func_t ) noise_think; }
void play_teleport() { float v; char *tmpstr; v = g_random() * 5; if ( v < 1 ) tmpstr = "misc/r_tele1.wav"; else if ( v < 2 ) tmpstr = "misc/r_tele2.wav"; else if ( v < 3 ) tmpstr = "misc/r_tele3.wav"; else if ( v < 4 ) tmpstr = "misc/r_tele4.wav"; else tmpstr = "misc/r_tele5.wav"; sound( self, CHAN_VOICE, tmpstr, 1, ATTN_NORM ); ent_remove( self ); }
void SP_misc_noisemaker( ) { if ( !CheckExistence( ) ) { dremove( self ); return; } trap_precache_sound( "enforcer/enfire.wav" ); trap_precache_sound( "enforcer/enfstop.wav" ); trap_precache_sound( "enforcer/sight1.wav" ); trap_precache_sound( "enforcer/sight2.wav" ); trap_precache_sound( "enforcer/sight3.wav" ); trap_precache_sound( "enforcer/sight4.wav" ); trap_precache_sound( "enforcer/pain1.wav" ); trap_precache_sound( "enforcer/pain2.wav" ); trap_precache_sound( "enforcer/death1.wav" ); trap_precache_sound( "enforcer/idle1.wav" ); self->s.v.nextthink = g_globalvars.time + 0.1 + g_random( ); self->s.v.think = ( func_t ) noise_think; }