Ejemplo n.º 1
0
OverlordAgent::OverlordAgent(Unit* mUnit)
{
    unit = mUnit;
    type = unit->getType();
    unitID = unit->getID();
    agentType = "OverlordAgent";
    //Broodwar->printf("OverlordAgent created (%s)", unit->getType().getName().c_str());

    lastUpdateFrame = Broodwar->getFrameCount();
    goal = TilePosition(-1, -1);
    updateGoal();
}
Ejemplo n.º 2
0
void OverlordAgent::computeActions()
{
    if (squadID == -1)
    {
        if (Broodwar->getFrameCount() - lastUpdateFrame > 100)
        {
            updateGoal();
        }
    }

    PFManager::Instance().computeAttackingUnitActions(this, goal, true);
}
Ejemplo n.º 3
0
void OverlordAgent::computeActions()
{
	if (squadID == -1)
	{
		if (Broodwar->getFrameCount() - lastUpdateFrame > 100)
		{
			updateGoal();
		}
	}

	NavigationAgent::getInstance()->computeMove(this, goal, true);
}
Ejemplo n.º 4
0
/**
* \fn int gameLoop(sInterface *p_interface, sMap *p_map)
* \brief Fonction de rendu de l'enigme et d'interfacage avec l'utilisateur
*
* \param *p_interface pointeur vers une structure de type sInterface
* \param *p_map pointeur vers une structure de type sMap
* \return int représentant le déroulement de la fonction
*/
int gameLoop(sInterface *p_interface, sMap *p_map) {
	
	bool l_loop = TRUE, l_solve = FALSE;
	char txtCmpt[32] = "";

	SDL_Rect l_posText = {(WINDOW_WIDTH / CASE_COLUMN_AMOUNT)/2, (WINDOW_HEIGHT / CASE_LINE_AMOUNT)/2, 50, 50};
	SDL_Color l_color = {255, 0, 0};

	p_interface->player.mapPosition.x = p_map->starting.x;
	p_interface->player.mapPosition.y = p_map->starting.y;
	p_interface->player.realPosition = getRealPosition(p_interface->player.mapPosition);
	p_interface->player.realDestination = getRealPosition(p_interface->player.mapPosition);

	displayMap(p_interface, p_map);

	while (l_loop){
		if(SDL_PollEvent(&(p_interface->event))) {
			switch (p_interface->event.type) {
				case(SDL_KEYDOWN):
					switch (p_interface->event.key.keysym.sym) {
						case(SDLK_z):
							updateGoal(p_interface, p_map, DUP);
							break;

						case(SDLK_d):
							updateGoal(p_interface, p_map, DRIGHT);
							break;

						case(SDLK_s):
							updateGoal(p_interface, p_map, DDOWN);
							break;

						case(SDLK_q):
							updateGoal(p_interface, p_map, DLEFT);	
							break;

						case(SDLK_x):
							l_solve = !l_solve;
							break;

						case(SDLK_ESCAPE):
							l_loop = FALSE;
							break;
					}
					break;

				case(SDL_MOUSEBUTTONDOWN):
					break;
			}
			while (SDL_PollEvent(&(p_interface->event)));
		}

		SDL_RenderClear(p_interface->renderer);
		SDL_RenderCopy(p_interface->renderer, p_interface->backgroundSprite, NULL, NULL);

		if(l_solve)
			showSolution(p_interface, p_interface->solution);
		renderParticle(&(p_interface->effect.particle), p_interface, p_map, TRUE);

		updateVision(p_interface, p_map);

		sprintf_s(txtCmpt, 30, "%d", p_interface->compteur);
		displayText(p_interface->renderer, txtCmpt, l_color, l_posText);


		SDL_RenderPresent(p_interface->renderer);
		if (WinOrNot(p_interface, p_map)) {
			l_loop = FALSE;
		}
		SDL_Delay(SDL_ANIMATION_FRAMETIME);
	}


	return 0;
}
Ejemplo n.º 5
0
GoToPose::GoToPose(Point targetPoint, float targetAngle, bool withObstacleAvoid, bool avoidBall)
{
    updateGoal(targetPoint, targetAngle, withObstacleAvoid, avoidBall);
}
Ejemplo n.º 6
0
    virtual void update() override
    {
        IUpdatable::update();
        
        uint64_t time = clock_->millis();

        //don't keep reading if not updated
        uint64_t dt = time - last_rec_read_;
        if (dt <= params_->rc.read_interval_ms)
            return;
        last_rec_read_ = time;

        //read channel values
        Axis4r channels;
        for (unsigned int axis = 0; axis < Axis4r::AxisCount(); ++axis) {
            channels[axis] = board_inputs_->isRcConnected() ?
                board_inputs_->readChannel(params_->rc.channels[axis])
                : 0;
        }

        //set goal mode as per the switch position on RC
        updateGoalMode();
        updateAllowApiControl();

        //get any special action being requested by user such as arm/disarm
        RcRequestType rc_action = getActionRequest(channels);

        //state machine
        switch (vehicle_state_->getState()) {
        case VehicleStateType::Inactive:
            //comm_link_->log(std::string("State:\t ").append("Inactive state"));

            if (rc_action == RcRequestType::ArmRequest) {
                comm_link_->log(std::string("State:\t ").append("Inactive state, Arm request recieved"));
                request_duration_ += dt;

                if (request_duration_ > params_->rc.arm_duration) {
                    vehicle_state_->setState(VehicleStateType::BeingArmed);
                    request_duration_ = 0;
                }
            }
            //else ignore
            break;
        case VehicleStateType::BeingArmed:
            comm_link_->log(std::string("State:\t ").append("Being armed"));

            //start the motors
            goal_ = Axis4r::zero(); //neural activation while still being armed
            goal_.throttle() = params_->Params::min_armed_throttle();

            //we must wait until sticks are at neutral or we will have random behaviour
            if (rc_action == RcRequestType::NeutralRequest) {
                request_duration_ += dt;

                if (request_duration_ > params_->rc.neutral_duration) {
                    state_estimator_->setHomeGeoPoint(state_estimator_->getGeoPoint());
                    vehicle_state_->setState(VehicleStateType::Armed, state_estimator_->getHomeGeoPoint());
                    comm_link_->log(std::string("State:\t ").append("Armed"));
                    request_duration_ = 0;
                }
            }
            //else ignore
            break;
        case VehicleStateType::Armed:
            //unless diarm is being requested, set goal from stick position
            if (rc_action == RcRequestType::DisarmRequest) {
                comm_link_->log(std::string("State:\t ").append("Armed state, disarm request recieved"));
                request_duration_ += dt;

                if (request_duration_ > params_->rc.disarm_duration) {
                    vehicle_state_->setState(VehicleStateType::BeingDisarmed);
                    request_duration_ = 0;
                }
            }
            else {
                request_duration_ = 0; //if there was spurious disarm request
                updateGoal(channels);
            }
            break;
        case VehicleStateType::BeingDisarmed:
            comm_link_->log(std::string("State:\t ").append("Being state"));

            goal_.setAxis3(Axis3r::zero()); //neutral activation while being disarmed
            vehicle_state_->setState(VehicleStateType::Disarmed);
            request_duration_ = 0;

            break;
        case VehicleStateType::Disarmed:
            comm_link_->log(std::string("State:\t ").append("Disarmed"));

            goal_ = Axis4r::zero(); //neutral activation while being disarmed
            vehicle_state_->setState(VehicleStateType::Inactive);
            request_duration_ = 0;

            break;
        default:
            throw std::runtime_error("VehicleStateType has unknown value for RemoteControl::update()");
        }
    }