~ubuntu-branches/ubuntu/precise/openarena/precise

« back to all changes in this revision

Viewing changes to code/game/ai_team.c

  • Committer: Bazaar Package Importer
  • Author(s): Ansgar Burchardt
  • Date: 2008-09-05 21:14:51 UTC
  • mfrom: (1.2.1 upstream) (2.1.5 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080905211451-243bmbl6l6gdav7l
* Remove non-free code/tools/lcc (Closes: #496346)
  + Remove hunk from patch 10_fix_build_and_binary_on_alpha
  + debian/rules: Add BUILD_GAME_QVM=0 to $(MAKE) call
    (thanks to Peter De Wachter)
* Remove code/libs containing binary libraries for Mac OS X and Win32
* debian/copyright: Explain which parts of upstream's sources were removed
* debian/rules: replace ${source:Upstream-Version} by 0.7.7
  because the variable also contains the `+dfsg1' part
* Add -fsigned-char to compiler options (Closes: #487970)
  (thanks to Peter De Wachter)
* Add myself to Uploaders
* debian/control: Remove article from beginning of short description,
  don't start short description with a capital letter
* debian/openarena.6: Escape minus signs
  + fixes lintian warnings: hyphen-used-as-minus-sign

Show diffs side-by-side

added added

removed removed

Lines of Context:
131
131
        int traveltimes[MAX_CLIENTS];
132
132
        bot_goal_t *goal = NULL;
133
133
 
134
 
        if (gametype == GT_CTF || gametype == GT_1FCTF) {
 
134
        if (gametype == GT_CTF || gametype == GT_1FCTF || gametype == GT_CTF_ELIMINATION) {
135
135
                if (BotTeam(bs) == TEAM_RED)
136
136
                        goal = &ctf_redflag;
137
137
                else
180
180
 
181
181
/*
182
182
==================
 
183
BotSortTeamMatesByReletiveTravelTime2ddA
 
184
For Double Domination
 
185
==================
 
186
*/
 
187
int BotSortTeamMatesByRelativeTravelTime2ddA(bot_state_t *bs, int *teammates, int maxteammates) {
 
188
        int i, j, k, numteammates;
 
189
        double traveltime, traveltime2b;
 
190
        char buf[MAX_INFO_STRING];
 
191
        static int maxclients;
 
192
        double traveltimes[MAX_CLIENTS];
 
193
        //int traveltimes2b[MAX_CLIENTS];
 
194
        bot_goal_t *goalA = &ctf_redflag;
 
195
        bot_goal_t *goalB = &ctf_blueflag;
 
196
 
 
197
        if (!maxclients)
 
198
                maxclients = trap_Cvar_VariableIntegerValue("sv_maxclients");
 
199
 
 
200
        numteammates = 0;
 
201
 
 
202
        for (i = 0; i < maxclients && i < MAX_CLIENTS; i++) {
 
203
                trap_GetConfigstring(CS_PLAYERS+i, buf, sizeof(buf));
 
204
                //if no config string or no name
 
205
                if (!strlen(buf) || !strlen(Info_ValueForKey(buf, "n"))) continue;
 
206
                //skip spectators
 
207
                if (atoi(Info_ValueForKey(buf, "t")) == TEAM_SPECTATOR) continue;
 
208
                if (BotSameTeam(bs, i)) {
 
209
                        traveltime = (double)BotClientTravelTimeToGoal(i, goalA);
 
210
                        traveltime2b = (double)BotClientTravelTimeToGoal(i, goalB);
 
211
                        traveltime = traveltime/traveltime2b;
 
212
 
 
213
                        for (j = 0; j < numteammates; j++) {
 
214
                                if (traveltime < traveltimes[j]) {
 
215
                                        for (k = numteammates; k > j; k--) {
 
216
                                                traveltimes[k] = traveltimes[k-1];
 
217
                                                teammates[k] = teammates[k-1];
 
218
                                        }
 
219
                                        break;
 
220
                                }
 
221
                        }
 
222
                        traveltimes[j] = traveltime;
 
223
                        teammates[j] = i;
 
224
                        numteammates++;
 
225
                        if (numteammates >= maxteammates) break;
 
226
                }
 
227
        }
 
228
 
 
229
        return numteammates;
 
230
}
 
231
 
 
232
/*
 
233
==================
183
234
BotSetTeamMateTaskPreference
184
235
==================
185
236
*/
448
499
        int numteammates, defenders, attackers, i;
449
500
        int teammates[MAX_CLIENTS];
450
501
        char name[MAX_NETNAME];
 
502
        qboolean weAreAttacking;
451
503
 
452
504
        numteammates = BotSortTeamMatesByBaseTravelTime(bs, teammates, sizeof(teammates));
453
505
        BotSortTeamMatesByTaskPreference(bs, teammates, numteammates);
 
506
 
 
507
        weAreAttacking = qfalse;
 
508
 
 
509
        //In oneway ctf we must all move out of the base (only one strategi, maybe we can also send some to the enemy base  to meet the flag carier?)
 
510
        //We must be defending
 
511
        if(g_elimination_ctf_oneway.integer > 0) {
 
512
                for (i = 0; i < numteammates; i++) {
 
513
                        //
 
514
                        ClientName(teammates[i], name, sizeof(name));
 
515
                        BotAI_BotInitialChat(bs, "cmd_getflag", name, NULL);
 
516
                        BotSayTeamOrder(bs, teammates[i]);
 
517
                        BotSayVoiceTeamOrder(bs, teammates[i], VOICECHAT_GETFLAG);
 
518
                }
 
519
                return;
 
520
        }
 
521
 
454
522
        //passive strategy
455
523
        if (!(bs->ctfstrategy & CTFS_AGRESSIVE)) {
456
524
                //different orders based on the number of team mates
682
750
        }
683
751
}
684
752
 
 
753
/*
 
754
==================
 
755
BotDDorders
 
756
==================
 
757
*/
 
758
 
 
759
void BotDDorders_Standard(bot_state_t *bs) {
 
760
        int numteammates, i;
 
761
        int teammates[MAX_CLIENTS];
 
762
        char name[MAX_NETNAME];
 
763
 
 
764
        //sort team mates by travel time to base
 
765
        numteammates = BotSortTeamMatesByRelativeTravelTime2ddA(bs, teammates, sizeof(teammates));
 
766
 
 
767
        switch(numteammates) {
 
768
                case 1: break;
 
769
                /*case 2: 
 
770
                {
 
771
                        //the one closest to point A will take that
 
772
                        ClientName(teammates[0], name, sizeof(name));
 
773
                        BotAI_BotInitialChat(bs, "cmd_takea", name, NULL);
 
774
                        BotSayTeamOrder(bs, teammates[0]);
 
775
                        //BotSayVoiceTeamOrder(bs, teammates[0], VOICECHAT_TAKEA);
 
776
                        //the other goes for point B
 
777
                        ClientName(teammates[1], name, sizeof(name));
 
778
                        BotAI_BotInitialChat(bs, "cmd_takeb", name, NULL);
 
779
                        BotSayTeamOrder(bs, teammates[1]);
 
780
                        //BotSayVoiceTeamOrder(bs, teammates[1], VOICECHAT_TAKEB);
 
781
                        break;
 
782
                }*/
 
783
                default:
 
784
                {
 
785
                        for(i=0;i<numteammates/2;i++) { //Half take point A
 
786
                                ClientName(teammates[i], name, sizeof(name));
 
787
                                BotAI_BotInitialChat(bs, "cmd_takea", name, NULL);
 
788
                                BotSayTeamOrder(bs, teammates[i]);
 
789
                                //BotSayVoiceTeamOrder(bs, teammates[0], VOICECHAT_TAKEA);
 
790
                        }
 
791
                        for(i=numteammates/2+1;i<numteammates;i++) { //Rest takes point B
 
792
                                ClientName(teammates[i], name, sizeof(name));
 
793
                                BotAI_BotInitialChat(bs, "cmd_takeb", name, NULL);
 
794
                                BotSayTeamOrder(bs, teammates[i]);
 
795
                                //BotSayVoiceTeamOrder(bs, teammates[0], VOICECHAT_TAKEB);
 
796
                        }
 
797
                        break;
 
798
                }
 
799
        }
 
800
}
685
801
 
686
802
/*
687
803
==================
692
808
        int numteammates, defenders, attackers, i;
693
809
        int teammates[MAX_CLIENTS];
694
810
        char name[MAX_NETNAME];
 
811
        qboolean weAreAttacking;
695
812
 
696
813
        //sort team mates by travel time to base
697
814
        numteammates = BotSortTeamMatesByBaseTravelTime(bs, teammates, sizeof(teammates));
698
815
        //sort team mates by CTF preference
699
816
        BotSortTeamMatesByTaskPreference(bs, teammates, numteammates);
 
817
 
 
818
        weAreAttacking = qfalse;
 
819
 
 
820
        if(g_elimination_ctf_oneway.integer > 0) {
 
821
                //See if we are attacking:
 
822
                if( ( (level.eliminationSides+level.roundNumber)%2 == 0 ) && (BotTeam(bs) == TEAM_RED))
 
823
                        weAreAttacking = qtrue;
 
824
                
 
825
                if(weAreAttacking) {
 
826
                        for (i = 0; i < numteammates; i++) {
 
827
                                //
 
828
                                ClientName(teammates[i], name, sizeof(name));
 
829
                                BotAI_BotInitialChat(bs, "cmd_getflag", name, NULL);
 
830
                                BotSayTeamOrder(bs, teammates[i]);
 
831
                                BotSayVoiceTeamOrder(bs, teammates[i], VOICECHAT_GETFLAG);
 
832
                        }
 
833
                } else {
 
834
                        for (i = 0; i < numteammates; i++) {
 
835
                                //
 
836
                                ClientName(teammates[i], name, sizeof(name));
 
837
                                BotAI_BotInitialChat(bs, "cmd_defendbase", name, NULL);
 
838
                                BotSayTeamOrder(bs, teammates[i]);
 
839
                                BotSayVoiceTeamOrder(bs, teammates[i], VOICECHAT_DEFEND);
 
840
                        }
 
841
                }
 
842
                return; //Sago: Or the leader will make a counter order.
 
843
        }
 
844
 
700
845
        //passive strategy
701
846
        if (!(bs->ctfstrategy & CTFS_AGRESSIVE)) {
702
847
                //different orders based on the number of team mates
844
989
        }
845
990
}
846
991
 
 
992
/*
 
993
==================
 
994
BotDDorders
 
995
==================
 
996
*/
 
997
void BotDDorders(bot_state_t *bs) {
 
998
        BotDDorders_Standard(bs);       
 
999
}
 
1000
 
847
1001
 
848
1002
/*
849
1003
==================
1922
2076
        return qfalse;
1923
2077
}
1924
2078
 
 
2079
int lastRoundNumber; //used to give new orders every round
 
2080
 
1925
2081
/*
1926
2082
==================
1927
2083
BotTeamAI
1932
2088
        char netname[MAX_NETNAME];
1933
2089
 
1934
2090
        //
1935
 
        if ( gametype < GT_TEAM  )
 
2091
        if ( gametype < GT_TEAM || g_ffa_gt == 1 )
1936
2092
                return;
1937
2093
        // make sure we've got a valid team leader
1938
2094
        if (!BotValidTeamLeader(bs)) {
1960
2116
                                BotSayVoiceTeamOrder(bs, -1, VOICECHAT_STARTLEADER);
1961
2117
                                ClientName(bs->client, netname, sizeof(netname));
1962
2118
                                strncpy(bs->teamleader, netname, sizeof(bs->teamleader));
1963
 
                                bs->teamleader[sizeof(bs->teamleader)] = '\0';
 
2119
                                bs->teamleader[sizeof(bs->teamleader)-1] = '\0';
1964
2120
                                bs->becometeamleader_time = 0;
1965
2121
                        }
1966
2122
                        return;
1992
2148
                        break;
1993
2149
                }
1994
2150
                case GT_CTF:
 
2151
                case GT_CTF_ELIMINATION:
1995
2152
                {
1996
2153
                        //if the number of team mates changed or the flag status changed
1997
2154
                        //or someone wants to know what to do
1998
 
                        if (bs->numteammates != numteammates || bs->flagstatuschanged || bs->forceorders) {
 
2155
                        if (bs->numteammates != numteammates || bs->flagstatuschanged || bs->forceorders || lastRoundNumber != level.roundNumber) {
1999
2156
                                bs->teamgiveorders_time = FloatTime();
2000
2157
                                bs->numteammates = numteammates;
2001
2158
                                bs->flagstatuschanged = qfalse;
2002
2159
                                bs->forceorders = qfalse;
 
2160
                                lastRoundNumber = level.roundNumber;
2003
2161
                        }
2004
2162
                        //if there were no flag captures the last 3 minutes
2005
2163
                        if (bs->lastflagcapture_time < FloatTime() - 240) {
2018
2176
                        }
2019
2177
                        break;
2020
2178
                }
 
2179
                case GT_DOUBLE_D:
 
2180
                {
 
2181
                        //if the number of team mates changed or the domination point status changed
 
2182
                        //or someone wants to know what to do
 
2183
                        if (bs->numteammates != numteammates || bs->flagstatuschanged || bs->forceorders) {
 
2184
                                bs->teamgiveorders_time = FloatTime();
 
2185
                                bs->numteammates = numteammates;
 
2186
                                bs->flagstatuschanged = qfalse;
 
2187
                                bs->forceorders = qfalse;
 
2188
                        }
 
2189
                        //if it's time to give orders
 
2190
                        if (bs->teamgiveorders_time && bs->teamgiveorders_time < FloatTime() - 3) {
 
2191
                                BotDDorders(bs);
 
2192
                                //
 
2193
                                bs->teamgiveorders_time = 0;
 
2194
                        }
 
2195
                        break;
 
2196
                }
2021
2197
#ifdef MISSIONPACK
2022
2198
                case GT_1FCTF:
2023
2199
                {