Exemplo n.º 1
0
/// Called every time an app is created
Extension::Extension(WObject* parent) : WObject(parent) {
    IURLs* urlManager = IURLs::instance();
    if (urlManager != 0)
        urlManager->urlSignal("/page").connect(this, &Extension::handleURLChange);
    dbSession().mapClass<Model>("page");
    actionMap.insert(ActionPair("view", &Extension::view));
    actionMap.insert(ActionPair("edit", &Extension::edit));
}
Exemplo n.º 2
0
	void Entity::initActionArray(Board& board, Environnement& env) 
	{
		_actionArray[WAIT] = ActionPair(WAIT_TIME, boost::bind(&Entity::wait, this));
		_actionArray[MOVE_UP] = ActionPair(MOVE_TIME, boost::bind(&Entity::goUp, this, boost::ref(board), boost::ref(env)));
		_actionArray[MOVE_DOWN] = ActionPair(MOVE_TIME, boost::bind(&Entity::goDown, this, boost::ref(board), boost::ref(env)));
		_actionArray[MOVE_LEFT] = ActionPair(MOVE_TIME, boost::bind(&Entity::goLeft, this, boost::ref(board), boost::ref(env)));
		_actionArray[MOVE_RIGHT] = ActionPair(MOVE_TIME, boost::bind(&Entity::goRight, this, boost::ref(board), boost::ref(env)));

		_newAction = Action(0, 0, boost::bind(&Entity::getNewAction, shared_from_this(), _1));
	}
Exemplo n.º 3
0
void Club::updateAttackingPlay()
{
	if (!stadium->gameIsOn)	return;

	float stadium_width = stadium->playArea.width;
	float stadium_height = stadium->playArea.height;
	float goalEffect = (onTheRightGoal)?(-1.0):(1.0);
	sf::Vector2f ball_pos = stadium->ball->getPosition2();
	sf::Vector2f relative_ball_pos = ball_pos;
	if (onTheRightGoal) 
	{
		relative_ball_pos.x = stadium->playArea.width - relative_ball_pos.x;
		relative_ball_pos.y = stadium->playArea.height - relative_ball_pos.y;
	}

	// Update currentDefensiveLine
	currentDefensiveLine = 0.12 * log(31.0*(relative_ball_pos.x/stadium->playArea.width)+1.0) /
		( log(2) * ((1.0/-0.9) * (defensiveLine-1.0) +1.0) );
	if(onTheRightGoal) currentDefensiveLine = 1.0 - currentDefensiveLine;
	currentDefensiveLine *= stadium->playArea.width;
	
	// Update currentLeftmost
	float minX = 2.0;
	for (int i=1; i<11; i++)
	{
		if (lineUp[i]->tactical_x<minX) minX = lineUp[i]->tactical_x;
	}
	
	float howFar_defLine = onTheRightGoal?currentDefensiveLine:(stadium->playArea.width-currentDefensiveLine);
	currentLeftmost = currentDefensiveLine - goalEffect * ( (minX * howFar_defLine) / (0.9-minX));
	currentWidth = 0.5 + 0.4 * attackingWidth;
	currentUppermost = ball_pos.y * (1.0-currentWidth);
	currentWidth *= stadium_height;

	findClosestPlayer();

	// If someone kicked the ball in the earlier frame, increase the time passed since the ball is kicked.
	if (sinceBallIsPassed>0) 
		sinceBallIsPassed += 1.0/60.0;

	SquadPosition* player;
	for (int j=0; j<11; j++)
	{
		player = lineUp[j];
		ActionMap possibleActions;
		for (int i=0; i<attackingActions.size(); i++)
		{
			float weight = attackingActions[i]->checkPreconditions(player,stadium);
			if (weight>0)
				possibleActions.insert( ActionPair(-1.0*weight,attackingActions[i]) );
		}
		if (possibleActions.size()>0)
			possibleActions.begin()->second->execute(player,stadium);
	}

};
Exemplo n.º 4
0
void Club::updateDefendingPlay()
{
	if (!stadium->gameIsOn)
		return;

	findClosestPlayer();

	float stadium_width = stadium->playArea.width;
	float stadium_height = stadium->playArea.height;
	float goalEffect = (onTheRightGoal)?(-1.0):(1.0);
	sf::Vector2f ball_pos = stadium->ball->getPosition2();
	sf::Vector2f relative_ball_pos = ball_pos;
	if (onTheRightGoal) 
	{
		relative_ball_pos.x = stadium->playArea.width - relative_ball_pos.x;
		relative_ball_pos.y = stadium->playArea.height - relative_ball_pos.y;
	}

	// Update currentDefensiveLine
	currentDefensiveLine = 0.08 * log(31.0*(relative_ball_pos.x/stadium->playArea.width)+1.0) / ( log(2) * ((1.0/-0.9) * (defensiveLine-1.0) +1.0) );
	if(onTheRightGoal) currentDefensiveLine = 1 - currentDefensiveLine;
	currentDefensiveLine *= stadium->playArea.width;

	// Update currentLeftmost
	float minX = 2.0;
	for (int i=1; i<11; i++)
	{
		if (lineUp[i]->defending_x<minX) minX = lineUp[i]->defending_x;
	}
	float howFar_defLine = ((onTheRightGoal)?(currentDefensiveLine):(stadium->playArea.width-currentDefensiveLine));
	currentLeftmost = currentDefensiveLine - goalEffect * ( (minX * howFar_defLine) / (1.0-minX));

	// Update currentUppermost
	currentWidth = 0.5 + 0.4 * defendingWidth;
	currentUppermost = ball_pos.y * (1.0-currentWidth);
	currentWidth *= stadium_height;

	SquadPosition* player;
	for (int j=0; j<11; j++)
	{
		player = lineUp[j];
		ActionMap possibleActions;
		for (int i=0; i<defendingActions.size(); i++)
		{
			float weight = defendingActions[i]->checkPreconditions(player,stadium);
			if (weight>0)
				possibleActions.insert( ActionPair(-weight,defendingActions[i]) );
		}
		if (possibleActions.size()>0)
			possibleActions.begin()->second->execute(player,stadium);
	}
};