D:\cygwin\wf_fusion_src_r8\CVSROOT\WeaponsFactory\WF_AI_MarineChooseWeapon.c

/*
==============================================================================
The Weapons Factory - 
  
Modified code by Keith Pase

Copyright (C) 1997-2003 Weapons Factory Software

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  

See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

  Code by Keith Pase

  WF_AI_MarineChooseWeapon.c -- Marine Weapon weight file, based on fusionbot.
  

==============================================================================
*/

#include "..\game\g_local.h"
#include "..\game\m_player.h"

#include "..\FusionSource\fusionbot.h"

void WF_AI_MarineChooseWeapon (edict_t *fusionbot)
{

    float   range;
    vec3_t  v;

    if(!fusionbot->enemy)
        return;

    VectorSubtract (fusionbot->s.origin, fusionbot->enemy->s.origin, v);

    range = VectorLength(v);
    
    fusionbot->usealt = 0;

    if (
        (strcmp(fusionbot->enemy->classname, "proximity") == 0)
        ||
        (fusionbot->enemy->botavoidgrenade == qtrue)
        )
    {
        if  (
            FUSION_AI_CheckShot(fusionbot) 
            && 
            FUSION_ITEMS_ChangeWeapon(fusionbot, FindItem("Rocket Launcher"))
            )
        {
            fusionbot->usealt = 0;
            return;
        }
    }

    if  (
        (strcmp(fusionbot->enemy->classname, "turret") == 0)
        ||
        (strcmp(fusionbot->enemy->classname, "laser_defense_gr") == 0)
        )
    {
        if  (
            FUSION_AI_CheckShot(fusionbot) 
            && 
            FUSION_ITEMS_ChangeWeapon(fusionbot, FindItem("Rocket Launcher"))
            )
        {
            fusionbot->usealt = 1;
            return;
        }
    }

    if  (
        (fusionbot->enemy->r.client)
        && 
        (
        (fusionbot->enemy->r.client->ctf_grapplestate == CTF_GRAPPLE_STATE_HANG ) ||
        (fusionbot->enemy->r.client->ctf_grapple) ||
        (fusionbot->enemy->r.client->thrusting)
        )
        )
    {
        if(FUSION_AI_CheckShot(fusionbot) && FUSION_ITEMS_ChangeWeapon(fusionbot, FindItem("Rocket Launcher")))
        {
            if(fusionbot->r.client->pers.inventory[ITEM_INDEX(FindItem("cells"))] > 4)
            {
                fusionbot->usealt = 1;
                return;
            }
        }
    }


    if(fusionbot->r.client->pers.inventory[ITEM_INDEX(FindItem("cells"))] > 10)
    {
        if (!(CTFHasFlag(fusionbot->enemy)))
        {
            if (random() > 0.5)
            {
                if (fusionbot->nextweaponthink < level.time )
                {
                    if  (
                        FUSION_AI_CheckShot(fusionbot) 
                        && 
                        FUSION_ITEMS_ChangeWeapon(fusionbot, FindItem("Hyperblaster"))
                        )
                    {
                        if (!(CTFHasFlag(fusionbot)))
                        {
                            if(range > 600)
                            {
                                fusionbot->usealt = 0;
                                fusionbot->delay2 = level.time + 3;
                                return;
                            }
                            else if (range < 600)
                            {
                                fusionbot->usealt = 1;
                                fusionbot->delay2 = level.time + 3;
                                return;
                            }
                        }
                        else
                        {
                            fusionbot->usealt = 1;
                            fusionbot->delay2 = level.time + 3;
                            return;
                        }
                    }

                    fusionbot->nextweaponthink = level.time + 5;
                }
                else
                {
                    fusionbot->delay2 = level.time + 3;
                    return;
                }
            }
        }
        else
        {
            if (range < 400)
            {
                if  (
                    FUSION_AI_CheckShot(fusionbot) 
                    && 
                    FUSION_ITEMS_ChangeWeapon(fusionbot, FindItem("Rocket Launcher"))
                    )
                {
                    if (range < 200)
                        fusionbot->usealt = 0;
                    else
                        fusionbot->usealt = 0;
                    return;
                }
            }
            else
            {
                if  (
                    FUSION_AI_CheckShot(fusionbot) 
                    && 
                    FUSION_ITEMS_ChangeWeapon(fusionbot, FindItem("Hyperblaster"))
                    )
                {
                    fusionbot->usealt = 0;
                    return;
                }
            }
        }
    }
    else
    {
        if  (
            FUSION_AI_CheckShot(fusionbot)
            && 
            FUSION_ITEMS_ChangeWeapon(fusionbot, FindItem("Rocket Launcher"))
            )
        {
            fusionbot->usealt = 0;
            fusionbot->delay2 = level.time + 3;
            return;
        }
    }

    return;
}