]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/tturrets/system/system_scoreprocs.qc
Merge branch 'master' into terencehill/newpanelhud
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / tturrets / system / system_scoreprocs.qc
1 /*
2 .float target_select_flags; /// target selection flags
3 float TFL_TARGETSELECT_NO            = 1;   /// Dont select a target on its own.
4 float TFL_TARGETSELECT_LOS           = 2;   /// Need line of sight
5 float TFL_TARGETSELECT_PLAYERS       = 4;   /// Players are valid targets
6 float TFL_TARGETSELECT_MISSILES      = 8;   /// Missiles are valid targets
7 float TFL_TARGETSELECT_TRIGGERTARGET = 16;  /// Responds to turret_trigger_target events
8 float TFL_TARGETSELECT_ANGLELIMITS   = 32;  /// Angular limitations of turret head limits target selection
9 float TFL_TARGETSELECT_RANGELIMTS    = 64;  /// Range limits apply in targetselection
10 float TFL_TARGETSELECT_TEAMCHECK     = 128; /// Consider team own <-> targets team
11 float TFL_TARGETSELECT_NOBUILTIN     = 256; /// Cant select targets on its own. needs to be triggerd or slaved.
12 float TFL_TARGETSELECT_OWNTEAM       = 512;
13 */
14
15 float turret_stdproc_targetscore_support(entity e_turret,entity e_target)
16 {
17     float score;        // Total score
18     float s_score,d_score;
19
20     if (e_turret.enemy == e_target) s_score = 1;
21
22     d_score = min(e_turret.target_range_optimal,tvt_dist) / max(e_turret.target_range_optimal,tvt_dist);
23
24     score = (d_score * e_turret.target_select_rangebias) +
25             (s_score * e_turret.target_select_samebias);
26
27     return score;
28 }
29
30 /*
31 * Generic bias aware score system.
32 */
33 float turret_stdproc_targetscore_generic(entity e_turret, entity e_target)
34 {
35     //vector v_tmp;
36     float d_dist;       // Defendmode Distance
37
38     float score;        // Total score
39
40     float d_score;      // Distance score
41     float a_score;      // Angular score
42     float m_score;      // missile score
43     float p_score;      // player score
44     //float da_score;   // Distance from aimpoint score
45
46     float ikr;          // ideal kill range
47
48     /*
49     if(!e_target) 
50                 return 0;
51         */
52
53     if (e_turret.tur_defend)
54     {
55         d_dist = vlen(real_origin(e_target) - e_turret.tur_defend.origin);
56         ikr = vlen(e_turret.origin - e_turret.tur_defend.origin);
57         d_score = 1 - d_dist / e_turret.target_range;
58     }
59     else
60     {
61         // Make a normlized value base on the targets distance from our optimal killzone
62         ikr = e_turret.target_range_optimal;
63         d_score = min(ikr,tvt_dist) / max(ikr,tvt_dist);
64     }
65
66     /*
67     // Determine the maximum time it could take this turrent to aim at someting.
68     max_aim_delay = (max(e_turret.aim_maxrot,e_turret.aim_maxpitch) / e_turret.aim_speed * 2);
69
70     // Find out how long it would take to aim at this taget.
71     aim_delay = (thadf+0.01) / e_turret.aim_speed;
72
73     // Turn this info into a normalized value.
74     aim_delay = (min(max_aim_delay,aim_delay) / max_aim_delay);
75     a_score = 1 - aim_delay;
76     */
77
78     //a_score = 1 - (tvt_thadf / max(e_turret.aim_maxrot,e_turret.aim_maxpitch));
79     a_score = 1 - tvt_thadf / e_turret.aim_maxrot;
80
81     if ((e_turret.target_select_missilebias > 0) && (e_target.flags & FL_PROJECTILE))
82         m_score = 1;
83
84     if ((e_turret.target_select_playerbias > 0) && (e_target.flags & FL_CLIENT))
85         p_score = 1;
86
87     d_score = max(d_score, 0);
88     a_score = max(a_score, 0);
89     m_score = max(m_score, 0);
90     p_score = max(p_score, 0);
91
92     score = (d_score * e_turret.target_select_rangebias) +
93             (a_score * e_turret.target_select_anglebias) +
94             (m_score * e_turret.target_select_missilebias) +
95             (p_score * e_turret.target_select_playerbias);
96
97     if(e_turret.target_range < vlen(e_turret.tur_shotorg - real_origin(e_target)))
98     {
99         dprint("Wtf?\n");
100         score *= 0.001;
101     }
102
103 #ifdef TURRET_DEBUG
104     string sd,sa,sm,sp,ss;
105     string sdt,sat,smt,spt;
106
107     sd = ftos(d_score);
108     d_score *= e_turret.target_select_rangebias;
109     sdt = ftos(d_score);
110
111     //sv = ftos(v_score);
112     //v_score *= e_turret.target_select_samebias;
113     //svt = ftos(v_score);
114
115     sa = ftos(a_score);
116     a_score *= e_turret.target_select_anglebias;
117     sat = ftos(a_score);
118
119     sm = ftos(m_score);
120     m_score *= e_turret.target_select_missilebias;
121     smt = ftos(m_score);
122
123     sp = ftos(p_score);
124     p_score *= e_turret.target_select_playerbias;
125     spt = ftos(p_score);
126
127
128     ss = ftos(score);
129     bprint("^3Target scores^7 \[  ",e_turret.netname, "  \] ^3for^7 \[  ", e_target.netname,"  \]\n");
130     bprint("^5Range:\[  ",sd,  "  \]^2+bias:\[  ",sdt,"  \]\n");
131     bprint("^5Angle:\[  ",sa,  "  \]^2+bias:\[  ",sat,"  \]\n");
132     bprint("^5Missile:\[  ",sm,"  \]^2+bias:\[  ",smt,"  \]\n");
133     bprint("^5Player:\[  ",sp, "  \]^2+bias:\[  ",spt,"  \]\n");
134     bprint("^3Total (w/bias):\[^1",ss,"\]\n");
135
136 #endif
137
138     return score;
139 }
140
141 /*
142 float turret_stdproc_targetscore_close(entity e_turret,entity e_target)
143 {
144     return 1 - (tvt_dist / e_turret.target_range);
145 }
146
147 float turret_stdproc_targetscore_far (entity e_turret,entity e_target)
148 {
149     return  tvt_dist / e_turret.target_range;
150 }
151
152 float turret_stdproc_targetscore_optimal(entity e_turret,entity e_target)
153 {
154     return  min(e_turret.target_range_optimal,tvt_dist) / max(e_turret.target_range_optimal,tvt_dist);
155 }
156
157 float turret_stdproc_score_angular(entity e_turret,entity e_target)
158 {
159     return 1 - (tvt_thadf / e_turret.aim_maxrot);
160 }
161
162 float turret_stdproc_targetscore_defend(entity e_turret,entity e_target)
163 {
164     return 0;
165     //min(e_target.origin,e_turret.tur_defend.origin) / max(e_target.origin,e_turret.tur_defend.origin);
166 }
167 */