Esempio n. 1
0
//returns true if captured, false otherwise
bool Map::captureStructure(uint8 x, uint8 y){
	Unit *unit = getUnitAt(x, y);
	Terrain *captureTerrain = getTerrainAt(x, y);
	if (!unit->isActive() || !captureTerrain->canBeCaptured()){
		return false;
	}

	bool captured = unit->capture();
	unit->deactivate();

	//Set owner if captured
	if (captured){
		m_terrain[x][y]->setOwner(unit->getOwner());
	}
	return captured;
}
Esempio n. 2
0
Unit* Map::produceUnit(uint8 x, uint8 y, CPlayer* owner, UnitType type)
{
	Terrain* pos = getTerrainAt(x, y);
	if (pos->getUnit() == NULL)
	{
		UnitBuilder builder(type, owner, newUnitId());
		Unit* newUnit = builder.getResult();

		//Add unit to map
		m_terrain[x][y]->setUnit(newUnit);

		//Add unit to unit list
		m_unitList[newUnit->getID()] = newUnit;
		return newUnit;
	}
	return NULL;
}
Esempio n. 3
0
//returns false if move is invalid or destination is occupied
bool Map::moveUnit(Unit* unit, uint8 new_x, uint8 new_y)
{
	//ensure unit can move onto newPos
	Coordinate unitPos = getUnitPos(unit->getID());
	if (!unit->isActive() || !MoveValidator::isMoveValid(unitPos.first, unitPos.second, new_x, new_y, unit, this)){
		return false;
	}

	Terrain* newTerrain = getTerrainAt(new_x, new_y);
	if (newTerrain->getUnit() == unit){
		return true;
	}
	//todo: implement fuel (not yet implemented on client)
	else if (newTerrain->setUnit(unit) == unit){
		if (unit->isCapturing()){
			unit->cancelCapture();
		}
		return true;
	}
	return false;
}
Esempio n. 4
0
SGSTerrain::Step SGSTerrain::moveHero(SGSHero* hero, STEP_DIRECTION one_step, Step step_from)
{
  Step step_to = step_from;

  Step current_step = step_from;
  SGSPoint origin_pos = hero->getMapPosition();

  SGSPoint left_pos = current_step.__pos;
  SGSPoint right_pos = current_step.__pos;
  SGSPoint up_pos = current_step.__pos;
  SGSPoint down_pos = current_step.__pos;

  left_pos.x--;
  right_pos.x++;
  up_pos.y--;
  down_pos.y++;

  bool is_original_pos = false;
  bool valid_move = true;

  if (origin_pos == current_step.__pos) {
    is_original_pos = true;
  }


  switch (one_step)
  {
  case STEP_RIGHT:
    step_to.__pos.x++;
    if (findHeroByPosition(right_pos) || getObj(right_pos)) {
      valid_move = false;
    }

    if (!is_original_pos) {
      if (hero->isRival(findHeroByPosition(up_pos)) || hero->isRival(findHeroByPosition(down_pos))) {
        valid_move = false;
      }
    }
    break;
  case STEP_DOWN:
    step_to.__pos.y++;
    if (findHeroByPosition(down_pos) || getObj(down_pos)) {
      valid_move = false;
    }

    if (!is_original_pos) {
      if (hero->isRival(findHeroByPosition(up_pos)) || hero->isRival(findHeroByPosition(right_pos))) {
        valid_move = false;
      }
    }
    break;
  case STEP_LEFT:
    step_to.__pos.x--;
    if (findHeroByPosition(left_pos) || getObj(left_pos)) {
      valid_move = false;
    }
    if (!is_original_pos) {
      if (hero->isRival(findHeroByPosition(up_pos)) || hero->isRival(findHeroByPosition(down_pos))) {
        valid_move = false;
      }
    }
    
    break;
  case STEP_UP:
    step_to.__pos.y--;
    if (findHeroByPosition(up_pos) || getObj(up_pos)) {
      valid_move = false;
    }
    if (!is_original_pos) {
      if (hero->isRival(findHeroByPosition(left_pos)) || hero->isRival(findHeroByPosition(right_pos))) {
        valid_move = false;
      }
    }
    break;
  default:
    break;
  }

 
  if (step_to.__pos.x < 0 || step_to.__pos.y < 0 || 
      step_to.__pos.x >= __width || step_to.__pos.y >= __height ||
      valid_move == false) {
    step_to.__stamina = -100;
  } else {
    step_to.__stamina -= getSteminaConsume(hero->getcategory(), getTerrainAt(step_to.__pos));
  }

  return step_to;
}