BWAPI
Public Member Functions | Private Attributes
SCVAgent Class Reference

#include <SCVAgent.h>

Inheritance diagram for SCVAgent:
Inheritance graph
[legend]
Collaboration diagram for SCVAgent:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 SCVAgent (BWAPI::Unit &u)
virtual void update ()

Private Attributes

BWAPI::TilePosition buildLocation
bool wasConstructing
BWAPI::Unit * constructingStructure

Detailed Description

Definition at line 10 of file SCVAgent.h.


Constructor & Destructor Documentation

SCVAgent::SCVAgent ( BWAPI::Unit &  u)

Definition at line 14 of file SCVAgent.cpp.


Member Function Documentation

void SCVAgent::update ( ) [virtual]

Reimplemented from GroundAgent.

Definition at line 20 of file SCVAgent.cpp.

References BWAPI::Broodwar, Agent::buildingLocation, Agent::buildingReserved, BuildState, constructingStructure, GatherState, IdleState, TacticalBuildingPlacer::instance(), TacticalBuildingPlacer::reserveBuildLocation(), Agent::state, Agent::unit, Agent::unitTarget, and Agent::unitTypeTarget.

{
        switch (state) {

                case IdleState:
                        // be idle
                        break;

                case GatherState:
                        // Gather minerals
                        if (unitTarget->getType().isMineralField()) 
                        {
                                if (!unit.isGatheringMinerals())
                                        unit.gather(unitTarget);
                        }

                        // Gather gas
                        else if (unitTarget->getType().isRefinery()) 
                        {
                                if (!unit.isGatheringGas())
                                        unit.gather(unitTarget);
                        }
                        break;

                case BuildState:
                        // Return cargo
                        //if (unit.isCarryingGas() ||   unit.isCarryingMinerals()) {
                        //      unit.returnCargo();
                        //}

                        // Done?
                        if (!unit.isConstructing() && constructingStructure != NULL)
                        {
                                if (constructingStructure->isCompleted())
                                {
                                        constructingStructure = NULL;
                                        buildingReserved = false;
                                        state = IdleState;
                                }
                        }

                        // Reserve a build location
                        else if (!buildingReserved)
                        {
                                TacticalBuildingPlacer &tbp = TacticalBuildingPlacer::instance();
                                buildingLocation = tbp.instance().reserveBuildLocation(unitTypeTarget, Broodwar->self()->getStartLocation(), &unit);
                                if (buildingLocation != TilePositions::None)
                                {
                                        buildingReserved = true;
                                }
                                unit.move(Position(buildingLocation));
                        }

                        // Build it
                        else if (buildingReserved && !unit.isConstructing())
                        {
                                unit.build(buildingLocation, unitTypeTarget);
                        }

                        // Building...
                        else if (unit.isConstructing())
                        {
                                constructingStructure = unit.getBuildUnit();
                        }
                        break;
        }

    GroundAgent::update();
}

Here is the call graph for this function:


Member Data Documentation

BWAPI::TilePosition SCVAgent::buildLocation [private]

Definition at line 17 of file SCVAgent.h.

BWAPI::Unit* SCVAgent::constructingStructure [private]

Definition at line 20 of file SCVAgent.h.

Referenced by update().

bool SCVAgent::wasConstructing [private]

Definition at line 18 of file SCVAgent.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines