Changeset 2307

Show
Ignore:
Timestamp:
06/10/12 19:13:42 (12 months ago)
Author:
palota
Message:

goal_checkdisguise: fixed chance to shoot was always 50% regardless of skill (mismatched parenthesis in if condition), reduced CPU usage (foreach loop is not executed every frame)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • Enemy-Territory/0.8/et/scripts/goals/goal_checkdisguise.gm

    r1072 r2307  
    1 // This script contains functionality to ignore disguised enemies if they arent close enough 
     1// This script contains functionality to ignore disguised enemies if they aren't close enough 
    22 
    33// These parameters are required 
     
    1919                gt = Util.GoalTable("PLANT_.*\nCHECKPOINT_.*\nFLAG_.*"); 
    2020 
    21                 foreach ( id and goal in gt ) { 
     21                foreach ( goal in gt ) { 
    2222                        i = tableCount( Map.PrimaryGoalPositions ); 
    23                         p = goal.GetPosition(); 
    2423                        Map.PrimaryGoalPositions[i] = goal.GetPosition(); 
    2524                        if ( this.Debug ) { 
     
    3231this.GetPriority = function() 
    3332{ 
    34         nearObj = false; 
    3533        t = this.Bot.GetTarget(); 
     34 
     35        // if they are close to a primary goal, just have the bots shoot them 
     36        foreach ( position in Map.PrimaryGoalPositions ) 
     37        { 
     38                if ( DistanceBetween(t, position) < 250 ) { 
     39                        if (this.Debug) { 
     40                                this.Bot.Say("I'm shooting a disguised target that is near primary objective, dist = " + this.Bot.DistanceTo(t)); 
     41                        } 
     42                        //wait until this thread is killed because target lost disguise after shooting 
     43                        block(0); 
     44                } 
     45        } 
     46 
     47        // map scripts can also define specific areas to always detect them 
     48        // key = position, value = radius 
     49        if ( Map.CovertDetectionSpots ) { 
     50                foreach ( location in Map.CovertDetectionSpots ) { 
     51                        if ( DistanceBetween(t, location[0]) <= location[1] ) { 
     52                                if (this.Debug) { 
     53                                        this.Bot.Say("I'm shooting a disguised target that is near CovertDetectionSpots, dist = " + this.Bot.DistanceTo(t)); 
     54                                } 
     55                                //wait until this thread is killed because target lost disguise after shooting 
     56                                block(0); 
     57                        } 
     58                } 
     59        } 
    3660 
    3761        while(1) 
    3862        { 
    39                 // if they are close to a primary goal, just have the bots shoot them 
    40                 foreach ( id and position in Map.PrimaryGoalPositions ) 
    41                 { 
    42                         if ( DistanceBetween(t, position) < 250 ) { 
    43                                 nearObj = true; 
    44                                 break; 
    45                         } 
    46                 } 
    47  
    48                 // map scripts can also define specific areas to always detect them 
    49                 // key = position, value = radius 
    50                 if ( Map && Map.CovertDetectionSpots ) { 
    51                         foreach ( location in Map.CovertDetectionSpots ) { 
    52                                 if ( DistanceBetween(t, location[0]) <= location[1] ) { 
    53                                         nearObj = true; 
    54                                         break; 
    55                                 } 
    56                         } 
    57                 } 
    58  
    5963                // increase odds of shooting with decreased distance to target 
    60                 if (this.Debug) { shootingDisguised = true; } 
    6164                dist = this.Bot.DistanceTo(t); 
    6265 
     
    6467                // f.e. if target is 300 units away and difficulty is 4 and there are 8 total players there is a 22% chance to shoot 
    6568                // while 20 total players would equal a 10% chance ... 
    66                 if ( !nearObj && ((dist > 1500) || (RandInt(0, ToInt(dist) > (50 + (10 * this.Bot.aimskill) - (3 * Server.NumPlayersNoSpec))))) ) { 
    67                         if (this.Debug) { shootingDisguised = false; } 
     69                if ( (dist > 1500) || RandInt(0, ToInt(dist)) > 50 + (10 * this.Bot.aimskill) - (3 * Server.NumPlayersNoSpec) ) { 
     70                        if (this.Debug) { 
     71                                this.Bot.Say("I'm ignoring a disguised target, dist = " + dist); 
     72                        } 
    6873                        this.Bot.IgnoreTarget( t, 10 - this.Bot.MemorySpan ); 
     74                        // wait until this thread is killed because this bot has no target, 
     75                        // (GetPriority will be called again after IgnoreTarget timeout) 
     76                        block(0); 
    6977                } 
    7078 
    71                 if ( this.Debug ) { 
    72                         if(shootingDisguised) { 
    73                                 this.Bot.Say("I'm shooting a disguised target: nearObj = " + nearObj + " dist = " + this.Bot.DistanceTo(t)); 
    74                         } 
    75                         else { 
    76                                 this.Bot.Say("I'm ignoring a disguised target: nearObj = " + nearObj + " dist = " + this.Bot.DistanceTo(t)); 
    77                         } 
     79                if (this.Debug) { 
     80                        this.Bot.Say("I'm shooting a disguised target, dist = " + dist); 
    7881                } 
    7982 
    80                 yield(); 
     83                sleep(0.5); 
    8184        } 
    8285};