Exemplo n.º 1
0
/**
 * Saves the soldier to a YAML file.
 * @param out YAML emitter.
 */
void BattleUnit::save(YAML::Emitter &out) const
{
	out << YAML::BeginMap;
 
	out << YAML::Key << "id" << YAML::Value << _id;
	out << YAML::Key << "faction" << YAML::Value << _faction;
	Soldier *soldier = dynamic_cast<Soldier*>(this->getUnit());
	if (soldier != 0)
	{
		out << YAML::Key << "soldierId" << YAML::Value << soldier->getId();
	}
	else
	{
		out << YAML::Key << "soldierId" << YAML::Value << -1;
	}
	out << YAML::Key << "name" << YAML::Value << Language::wstrToUtf8(_unit->getName(0));
	out << YAML::Key << "status" << YAML::Value << _status;
	out << YAML::Key << "position" << YAML::Value << YAML::Flow;
	out << YAML::BeginSeq << _pos.x << _pos.y << _pos.z << YAML::EndSeq;
	out << YAML::Key << "direction" << YAML::Value << _direction;
	out << YAML::Key << "tu" << YAML::Value << _tu;
	out << YAML::Key << "health" << YAML::Value << _health;
	out << YAML::Key << "energy" << YAML::Value << _energy;
	out << YAML::Key << "morale" << YAML::Value << _morale;
	out << YAML::Key << "kneeled" << YAML::Value << _kneeled;
	out << YAML::Key << "armor" << YAML::Value;
	out << YAML::Flow << YAML::BeginSeq;
	for (int i=0; i < 5; i++) out << _armor[i];
	out << YAML::EndSeq;
	out << YAML::Key << "fatalWounds" << YAML::Value;
	out << YAML::Flow << YAML::BeginSeq;
	for (int i=0; i < 6; i++) out << _fatalWounds[i];
	out << YAML::EndSeq;
	out << YAML::Key << "fire" << YAML::Value << _fire;
	out << YAML::Key << "expBravery" << YAML::Value << _expBravery;
	out << YAML::Key << "expReactions" << YAML::Value << _expReactions;
	out << YAML::Key << "expFiring" << YAML::Value << _expFiring;
	out << YAML::Key << "expThrowing" << YAML::Value << _expThrowing;
	out << YAML::Key << "expPsiSkill" << YAML::Value << _expPsiSkill;
	out << YAML::Key << "expMelee" << YAML::Value << _expMelee;

	if (getCurrentAIState())
	{
		out << YAML::Key << "AI" << YAML::Value;
		getCurrentAIState()->save(out);
	}
               
	out << YAML::EndMap;
}
Exemplo n.º 2
0
void UnitDieBState::init()
{
	// don't show the "fall to death" animation when a unit is blasted with explosives or he is already unconscious
	if (_damageType == DT_HE || _unit->getStatus() == STATUS_UNCONSCIOUS)
	{
		_unit->startFalling();
		while (_unit->getStatus() == STATUS_FALLING)
		{
			_unit->keepFalling();
		}
	}
	else
	{
		_parent->getMap()->getCamera()->centerOnPosition(_unit->getPosition());
		_parent->setStateInterval(BattlescapeState::DEFAULT_ANIM_SPEED);
		_unit->lookAt(3);
	}
	if (_unit->getHealth() == 0 && !_noSound)
	{
		Soldier *s = dynamic_cast<Soldier*>(_unit->getUnit());
		if (s)
		{
			// soldiers have screams depending on gender
			if (s->getGender() == GENDER_MALE)
			{
				_parent->getGame()->getResourcePack()->getSoundSet("BATTLE.CAT")->getSound(RNG::generate(41,43))->play();
			}
			else
			{
				_parent->getGame()->getResourcePack()->getSoundSet("BATTLE.CAT")->getSound(RNG::generate(44,46))->play();
			}
		}
		else
		{
			// todo get death sound from RuleGenUnit
			if (_unit->getUnit()->getArmor()->getSize() > 1)
			{
				// HWP destroy sound
				_parent->getGame()->getResourcePack()->getSoundSet("BATTLE.CAT")->getSound(23)->play();
			}
			else
			{
				_parent->getGame()->getResourcePack()->getSoundSet("BATTLE.CAT")->getSound(10)->play();
			}
		}
	}

	//think();
}
Exemplo n.º 3
0
//---------- Begin of function FirmCamp::pay_expense --------//
//
// pay_expense() is called by Firm::next_day()
//
void FirmCamp::pay_expense()
{
	if( !nation_recno )
		return;

	Firm::pay_expense();

	//-------- pay expenses to human units and weapons --------//

	Soldier* soldierPtr = soldier_array;
	Nation* nationPtr = nation_array[nation_recno];

	for( int i=1 ; i<=soldier_count ; i++, soldierPtr++ )
	{
		if( soldierPtr->is_under_training() )
			continue;

		// #### begin Gilbert 24/3 #####//
		// int unitClass = unit_res[soldierPtr->unit_id]->unit_class;

		//------ if the unit is a weapon -------//

		// if( unitClass == UNIT_CLASS_WEAPON )
		// one has life reduce hp when no food
		// one has no life, reduce hp when no money
		if( !unit_res[soldierPtr->unit_id]->class_info.life )
		// #### end Gilbert 24/3 #####//
		{
			if( nationPtr->cash > 0 )
			{
				nationPtr->add_expense( EXPENSE_WEAPON,
					(float) unit_res[soldierPtr->unit_id]->year_cost / 365, 1 );
			}
			else
			{
				//-- if it's a weapon, decrease hit points if the nation cannot pay the unit --//

				if( soldierPtr->hit_points > 0 )
					soldierPtr->hit_points--;

				if( soldierPtr->hit_points == 0 )
					kill_soldier(i);		// if its hit points is zero, delete it

				err_when( soldierPtr->hit_points < 0 );
			}
		}
	}
}
Exemplo n.º 4
0
/**
 * Handles the higher promotions (not the rookie-squaddie ones).
 * @return Whether or not some promotions happened - to show the promotions screen.
 */
bool SavedGame::handlePromotions()
{
	int soldiersPromoted = 0;
	int soldiersTotal = 0;

	for (std::vector<Base*>::iterator i = _bases.begin(); i != _bases.end(); ++i)
	{
		soldiersTotal += (*i)->getSoldiers()->size();
	}
	Soldier *highestRanked;
	
	// now determine the number of positions we have of each rank,
	// and the soldier with the heighest promotion score of the rank below it

	int filledPositions = 0, filledPositions2 = 0;
	inspectSoldiers(&filledPositions, RANK_COMMANDER);
	highestRanked = inspectSoldiers(&filledPositions2, RANK_COLONEL);
	if (filledPositions < 1 && filledPositions2 > 0)
	{
		// only promote one colonel to commander
		highestRanked->promoteRank();
		soldiersPromoted++;
	}
	inspectSoldiers(&filledPositions, RANK_COLONEL);
	highestRanked = inspectSoldiers(&filledPositions2, RANK_CAPTAIN);
	if (filledPositions < (soldiersTotal / 23) && filledPositions2 > 0)
	{
		highestRanked->promoteRank();
		soldiersPromoted++;
	}
	inspectSoldiers(&filledPositions, RANK_CAPTAIN);
	highestRanked = inspectSoldiers(&filledPositions2, RANK_SERGEANT);
	if (filledPositions < (soldiersTotal / 11) && filledPositions2 > 0)
	{
		highestRanked->promoteRank();
		soldiersPromoted++;
	}
	inspectSoldiers(&filledPositions, RANK_SERGEANT);
	highestRanked = inspectSoldiers(&filledPositions2, RANK_SQUADDIE);
	if (filledPositions < (soldiersTotal / 5) && filledPositions2 > 0)
	{
		highestRanked->promoteRank();
		soldiersPromoted++;
	}

	return (soldiersPromoted > 0);
}
Exemplo n.º 5
0
/**
 * Update soldier stats when the soldier changes.
 */
void InventoryState::init()
{
	BattleUnit *unit = _battleGame->getSelectedUnit();

	unit->setCache(0);
	_soldier->clear();
	_btnRank->clear();

	_txtName->setText(unit->getName(_game->getLanguage()));
	_inv->setSelectedUnit(unit);
	Soldier *s = _game->getSavedGame()->getSoldier(unit->getId());
	if (s)
	{
		SurfaceSet *texture = _game->getResourcePack()->getSurfaceSet("BASEBITS.PCK");
		texture->getFrame(s->getRankSprite())->setX(0);
		texture->getFrame(s->getRankSprite())->setY(0);
		texture->getFrame(s->getRankSprite())->blit(_btnRank);

		std::string look = s->getArmor()->getSpriteInventory();
		if (s->getGender() == GENDER_MALE)
			look += "M";
		else
			look += "F";
		if (s->getLook() == LOOK_BLONDE)
			look += "0";
		if (s->getLook() == LOOK_BROWNHAIR)
			look += "1";
		if (s->getLook() == LOOK_ORIENTAL)
			look += "2";
		if (s->getLook() == LOOK_AFRICAN)
			look += "3";
		look += ".SPK";
		if (!CrossPlatform::fileExists(CrossPlatform::getDataFile("UFOGRAPH/" + look)))
		{
			look = s->getArmor()->getSpriteInventory() + ".SPK";
		}
		_game->getResourcePack()->getSurface(look)->blit(_soldier);
	}
	if (_tu)
	{
		std::wstringstream ss;
		ss << _game->getLanguage()->getString("STR_TUS") << L'\x01' << unit->getTimeUnits();
		_txtTus->setText(ss.str());
	}
}
Exemplo n.º 6
0
/**
 * Equips the armor on the soldier and returns to the previous screen.
 * @param action Pointer to an action.
 */
void SoldierArmorState::lstArmorClick(Action *)
{
	Soldier *soldier = _base->getSoldiers()->at(_soldier);
	if (_game->getSavedGame()->getMonthsPassed() != -1)
	{
		if (soldier->getArmor()->getStoreItem() != "STR_NONE")
		{
			_base->getItems()->addItem(soldier->getArmor()->getStoreItem());
		}
		if (_armors[_lstArmor->getSelectedRow()]->getStoreItem() != "STR_NONE")
		{
			_base->getItems()->removeItem(_armors[_lstArmor->getSelectedRow()]->getStoreItem());
		}
	}
	soldier->setArmor(_armors[_lstArmor->getSelectedRow()]);

	_game->popState();
}
Exemplo n.º 7
0
//Deletes all of the created objects here.
void CloseFunc(){
	window.window_handle = -1;
	cylinder.TakeDown();torus.TakeDown();square.TakeDown();square2.TakeDown();
	disc.TakeDown();sphere.TakeDown();sphere2.TakeDown();tiger.TakeDown();goldeen.TakeDown();
	stadium.TakeDown();coin.TakeDown();ss.TakeDown();healthBar.TakeDown();
	shark.TakeDown();bird.TakeDown();sb.TakeDown();arena.TakeDown();skyboxUW.TakeDown();fbo.TakeDown();rain2.TakeDown();
	tri2.TakeDown();skybox.TakeDown();skybox2.TakeDown();skybox3.TakeDown();egg.TakeDown();snow2.TakeDown();
	star.TakeDown();magneton.TakeDown();haunter.TakeDown();frog.TakeDown();
	sph1.TakeDown(); enm.TakeDown(); usr.TakeDown();sq4.TakeDown();soldier.TakeDown();userTeam.TakeDown();cpuTeam.TakeDown();
}
Exemplo n.º 8
0
void Controller::generate()
{
	int random_number  = randomInt(1,100);
	if(random_number<51&&WarriorList->getSize()<25)
	{
		Pirate *p = new Pirate();
		p->setX(0);
		p->setY(randomInt(1,6));
		WarriorList->push(p);
		
	}
	if(random_number>34&&WarriorList->getSize()<25)
	{
		Soldier *s = new Soldier();
		s->setY(randomInt(2,4));
		s->setX(24);
		WarriorList->push(s);
	}
}
Exemplo n.º 9
0
//------- Begin of function FirmCamp::basic_train -------//
//
// Training a villager into a soldier.
//
void FirmCamp::basic_train()
{
	if( game.game_mode == GAME_TUTORIAL && 
		nation_recno != nation_array.player_recno)
		return;
	
	for( int i = 1; i <= soldier_count; ++i )
	{
		Soldier *soldierPtr = soldier_array + i - 1;

		// ###### begin Gilbert 19/11 #######//
		if( soldierPtr->is_under_training() )
		{
			int basicCombatLevel = BASIC_COMBAT_TRAIN;
			// ###### patch begin Gilbert 16/2 ######//
			// if( nation_recno && soldierPtr->race_id == RACE_ROMAN 
			//	&& god_res[GOD_ROMAN]->nation_prayer_count(nation_recno) > 0 )
			if( nation_recno && god_res[GOD_ROMAN]->nation_prayer_count(nation_recno) > 0 )
			{
				basicCombatLevel += BASIC_COMBAT_TRAIN / 2;		// roman can train to combat level 30
			}
			// ###### patch end Gilbert 16/2 ######//

			int totalBuildDays = unit_res[soldierPtr->unit_id]->build_days;
			soldierPtr->skill.inc_combat_level( ((float) basicCombatLevel + 0.125f)/ totalBuildDays );
			soldierPtr->skill.inc_skill_level( ((float) BASIC_SKILL_TRAIN + 0.125f) / totalBuildDays );
			// add a little more to avoid truncation error

			soldierPtr->hit_points = soldierPtr->max_hit_points();

			if( soldierPtr->hit_points > soldierPtr->max_hit_points() )
				soldierPtr->hit_points = soldierPtr->max_hit_points();

			--soldierPtr->remain_build_days;
			err_when( soldierPtr->remain_build_days < 0 );

		// ###### end Gilbert 19/11 #######//

			break;		// only train one unit at a time.
		}
	}
}
Exemplo n.º 10
0
//--------- Begin of function FirmCamp::detect_soldier_info ---------//
//
void FirmCamp::detect_soldier_info()
{
	int dispY1 = disp_soldier_info_y1;

	if( selected_soldier_id==0 )		// display overseer info
	{
		detect_overseer_info();
		return;
	}

	if( selected_soldier_id > 0 && selected_soldier_id <= soldier_count )
	{
		int x=INFO_X1+20, y=dispY1;
		Soldier *soldierPtr = soldier_array + selected_soldier_id - 1;
		UnitInfo *unitInfo = unit_res[soldierPtr->unit_id];

		if( unitInfo->class_info.has_loyalty && nation_recno
			&& mouse.single_click( x, y+14, x+79 , y+27 ) )
		{
			// detect loyalty
			disp_combat_or_skill = 4;
		}
		else if( unitInfo->class_info.has_combat_level
			&& mouse.single_click( x+110, y+14, x+189, y+27 ) )
		{
			// detect combat level
			disp_combat_or_skill = 1;
		}
		else if( unitInfo->class_info.has_skill_level
			&& soldierPtr->skill_level() > 0
			&& mouse.single_click( x+110, y+28, x+189, y+41 ) )
		{
			// detect skill
			disp_combat_or_skill = 2;
		}
		else if( mouse.single_click( x-4, y-4, x+200, y+47 ) )
		{
			disp_combat_or_skill = 0;
		}
	}
}
Exemplo n.º 11
0
/**
 * Shows the Select Armor window.
 * @param action Pointer to an action.
 */
void CraftArmorState::lstSoldiersClick(Action *action)
{	
	Soldier *s = _base->getSoldiers()->at(_lstSoldiers->getSelectedRow());
	if (!(s->getCraft() && s->getCraft()->getStatus() == "STR_OUT"))
	{
		if (action->getDetails()->button.button == SDL_BUTTON_LEFT)
		{
			_game->pushState(new SoldierArmorState(_base, _lstSoldiers->getSelectedRow()));
		}
		else
		{
			if (_game->getSavedGame()->getMonthsPassed() != -1)
			{
				SavedGame *_save;
				_save = _game->getSavedGame();
				Armor *a = _game->getRuleset()->getArmor(_save->getLastSelectedArmor());
				if (_base->getItems()->getItem(a->getStoreItem()) > 0 || a->getStoreItem() == "STR_NONE")
				{
					if (s->getArmor()->getStoreItem() != "STR_NONE")
					{
						_base->getItems()->addItem(s->getArmor()->getStoreItem());
					}
					if (a->getStoreItem() != "STR_NONE")
					{
						_base->getItems()->removeItem(a->getStoreItem());
					}
					
					s->setArmor(a);
					_lstSoldiers->setCellText(_lstSoldiers->getSelectedRow(), 2, tr(a->getType()));
				}
			}
		}
	}
}
Exemplo n.º 12
0
//------------------------------------------------------------------------------
bool Application::mousePressed(const OIS::MouseEvent &evt, OIS::MouseButtonID id)
{
  // Base application logic
  if(!BaseApplication::mousePressed(evt, id))
    return false;


  // Left mouse button down
  if (id == OIS::MB_Left)
  {
    // Set mouse state
    l_mouse = true;

    // Select Soldiers under cursor
    Soldier* selection;
    if(getSoldierCollision(getMouseRay(evt.state), &selection))
      selection->setSelected(!selection->isSelected());
    else
      // Move Soldiers to empty area if nothing to select
      for(SoldierIter i = soldiers.begin(); i != soldiers.end(); i++)
        if(i->second->isSelected())
          i->second->addWaypoint(focus);
  }

  // Right mouse button down
  else if (id == OIS::MB_Right)
  {
    // Set mouse state
    r_mouse = true;

    // Create a new Soldier
    Soldier* new_soldier = new Soldier();
    new_soldier->attach(soldiers, scene, focus);
  }

  // consume event
  return true;
}
Exemplo n.º 13
0
//------- Begin of function FirmCamp::recover_hit_point -------//
//
// Soldiers recover their hit points.
//
// No need to recover the hit points of the general here as
// this is taken care in the Unit class function of the general.
//
void FirmCamp::recover_hit_point()
{
	Soldier* soldierPtr = soldier_array;

	for( int i=0 ; i<soldier_count ; i++, soldierPtr++ )
	{
		int hpInc = 1;
		short maxHp = soldierPtr->max_hit_points();

		//------- item effect -------- //

		hpInc += ( 1 + soldierPtr->item.ability(ITEM_ABILITY_RECOVERY) ) / 2;

		// ####### begin Gilbert 24/6 ########//
		// high max_hit_points recover faster
		// integer algorithm to increase maxHp / 200

		// /8 because recover_hit_point is called every 8 days
		// %200 for to recover maxHp/200 
		int cycle = (info.game_date / 8 ) % 200;
		cycle += 200;		// because cycle is going to be subtracted, avoid negative
		hpInc += (cycle * maxHp / 200) - ((cycle - 1) * maxHp / 200);

		// ####### end Gilbert 24/6 ########//

		//------- increase soldier hit points --------//

		if( soldierPtr->hit_points < maxHp )
		{
			soldierPtr->hit_points += hpInc;

			if( soldierPtr->hit_points > maxHp )
				soldierPtr->hit_points = maxHp;
		}
	}
}
Exemplo n.º 14
0
bool Soldier::hurtToOther(float atk)
{
    Level* level = dynamic_cast<Level*>(this->getParent());
    if (level == NULL)
    {
        return false;
    }
    
    CCArray* soldiers = level->_soldiers;
    CCObject* et = NULL;
    CCARRAY_FOREACH(soldiers, et)
    {
        Soldier* soldier = dynamic_cast<Soldier*>(et);
        if (soldier == NULL)
        {
            continue;
        }
        
        if (soldier->bearHurt())
        {
            soldier->atkHandler(atk, NULL);
            return true;
        }
    }
Exemplo n.º 15
0
//--------- Begin of function sort_soldier_id_function ---------//
//
static int sort_soldier_id_function( const void *va, const void *vb )
{
	Soldier *a = &cur_firm_ptr->soldier_array[*((short*)va) - 1];
	Soldier *b = &cur_firm_ptr->soldier_array[*((short*)vb) - 1];

	int rc = a->is_under_training() - b->is_under_training();

	if( rc == 0 )
		return int( b->skill_level() - a->skill_level() );
	else
		return rc;
}
Exemplo n.º 16
0
//--------- Begin of function sort_soldier_function ---------//
//
static int sort_soldier_function( const void *va, const void *vb )
{
	Soldier *a = (Soldier *)va;
	Soldier *b = (Soldier *)vb;

	int rc = a->is_under_training() - b->is_under_training();

	if( rc == 0 )
		return int( b->skill_level() - a->skill_level() );
	else
		return rc;
}
Exemplo n.º 17
0
/**
 * Update soldier stats when the soldier changes.
 */
void InventoryState::init()
{
	BattleUnit *unit = _battleGame->getSelectedUnit();
	unit->setCache(0);
	_soldier->clear();
	_btnRank->clear();

	_txtName->setText(unit->getUnit()->getName(_game->getLanguage()));
	_inv->setSelectedUnit(unit);
	Soldier *s = dynamic_cast<Soldier*>(unit->getUnit());
	if (s)
	{
		SurfaceSet *texture = _game->getResourcePack()->getSurfaceSet("BASEBITS.PCK");
		texture->getFrame(s->getRankSprite())->setX(0);
		texture->getFrame(s->getRankSprite())->setY(0);
		texture->getFrame(s->getRankSprite())->blit(_btnRank);

		std::string look = "MAN_0";
		if (s->getGender() == GENDER_MALE)
			look += "M";
		else
			look += "F";
		if (s->getLook() == LOOK_BLONDE)
			look += "0";
		if (s->getLook() == LOOK_BROWNHAIR)
			look += "1";
		if (s->getLook() == LOOK_ORIENTAL)
			look += "2";
		if (s->getLook() == LOOK_AFRICAN)
			look += "3";
		look += ".SPK";
		_game->getResourcePack()->getSurface(look)->blit(_soldier);
	}
	if (_tu)
	{
		std::wstringstream ss;
		ss << _game->getLanguage()->getString("STR_TUS") << L'\x01' << unit->getTimeUnits();
		_txtTus->setText(ss.str());
	}
}
Exemplo n.º 18
0
/**
 * Shows the Select Armor window.
 * @param action Pointer to an action.
 */
void CraftArmorState::lstSoldiersClick(Action *action)
{
	Soldier *s = _base->getSoldiers()->at(_lstSoldiers->getSelectedRow());
	if (!(s->getCraft() && s->getCraft()->getStatus() == "STR_OUT"))
	{
		if (action->getDetails()->button.button == SDL_BUTTON_LEFT)
		{
			_game->pushState(new SoldierArmorState(_base, _lstSoldiers->getSelectedRow()));
		}
		else if (action->getDetails()->button.button == SDL_BUTTON_RIGHT)
		{
			SavedGame *save;
			save = _game->getSavedGame();
			Armor *a = _game->getMod()->getArmor(save->getLastSelectedArmor());
			if (a && (a->getUnits().empty() || std::find(a->getUnits().begin(), a->getUnits().end(), s->getRules()->getType()) != a->getUnits().end()))
			{
				if (save->getMonthsPassed() != -1)
				{
					if (_base->getStorageItems()->getItem(a->getStoreItem()) > 0 || a->getStoreItem() == Armor::NONE)
					{
						if (s->getArmor()->getStoreItem() != Armor::NONE)
						{
							_base->getStorageItems()->addItem(s->getArmor()->getStoreItem());
						}
						if (a->getStoreItem() != Armor::NONE)
						{
							_base->getStorageItems()->removeItem(a->getStoreItem());
						}

						s->setArmor(a);
						_lstSoldiers->setCellText(_lstSoldiers->getSelectedRow(), 2, tr(a->getType()));
					}
				}
				else
				{
					s->setArmor(a);
					_lstSoldiers->setCellText(_lstSoldiers->getSelectedRow(), 2, tr(a->getType()));
				}
			}
		}
	}
}
Exemplo n.º 19
0
/**
 * Shows the selected soldier's info.
 * @param action Pointer to an action.
 */
void CraftSoldiersState::lstSoldiersClick(Action *action)
{
	double mx = action->getAbsoluteXMouse();
	if ( mx >= _lstSoldiers->getArrowsLeftEdge() && mx < _lstSoldiers->getArrowsRightEdge() )
	{
		return;
	}
	int row = _lstSoldiers->getSelectedRow();
	if (action->getDetails()->button.button == SDL_BUTTON_LEFT)
	{
		Craft *c = _base->getCrafts()->at(_craft);
		Soldier *s = _base->getSoldiers()->at(_lstSoldiers->getSelectedRow());
		Uint8 color = Palette::blockOffset(13)+10;
		if (s->getCraft() == c)
		{
			s->setCraft(0);
			_lstSoldiers->setCellText(row, 2, tr("STR_NONE_UC"));
			color = Palette::blockOffset(13)+10;
		}
		else if (s->getCraft() && s->getCraft()->getStatus() == "STR_OUT")
		{
			color = Palette::blockOffset(15)+6;
		}
		else if (c->getSpaceAvailable() > 0 && s->getWoundRecovery() == 0)
		{
			s->setCraft(c);
			_lstSoldiers->setCellText(row, 2, c->getName(_game->getLanguage()));
			color = Palette::blockOffset(13);
		}
		_lstSoldiers->setRowColor(row, color);

		_txtAvailable->setText(tr("STR_SPACE_AVAILABLE").arg(c->getSpaceAvailable()));
		_txtUsed->setText(tr("STR_SPACE_USED").arg(c->getSpaceUsed()));
	}
	else if (action->getDetails()->button.button == SDL_BUTTON_RIGHT)
	{
		_game->pushState(new SoldierInfoState(_game, _base, row));
	}
}
Exemplo n.º 20
0
//------- Begin of function FirmCamp::advanced_train -------//
//
// Increase the leadership and ocmbat level of the general and the soldiers.
//
void FirmCamp::advanced_train()
{
	if( game.game_mode == GAME_TUTORIAL && 
		nation_recno != nation_array.player_recno)
		return;
	
	if( !overseer_recno )
		return;

	Unit* overseerUnit = unit_array[overseer_recno];

	int overseerSkill = (int) overseerUnit->skill_level();
								// + overseerUnit->item.ability( ITEM_ABILITY_SKILL_LEVEL );
								// skill_level() already contain enhancement
	int incValue;

	//------- increase the commander's leadership ---------//

	if( soldier_count > 0
		 && (int) overseerUnit->skill_level() < MAX_SKILL_TRAIN ) // do not use overseerSkill
	{
		//-- the more soldiers this commander has, the higher the leadership will increase ---//

		incValue = 5 * soldier_count
					  * (int) overseerUnit->hit_points / overseerUnit->max_hit_points()
					  * (100+overseerUnit->skill.skill_potential*2) / 100;

		// AI_CHEAT

		if( is_ai && config.ai_aggressiveness > OPTION_MODERATE )
			incValue += incValue * (config.ai_aggressiveness-OPTION_MODERATE) / 3;		// 33% faster if aggressivness is high, 66% faster if aggressiveness is very high

		overseerUnit->skill.inc_skill_level( (float)incValue/100 );
	}

	//------- increase the commander's combat level ---------//

	if( overseerUnit->combat_level() < MAX_COMBAT_TRAIN )
	{
		incValue = 10 * (int) overseerUnit->hit_points / overseerUnit->max_hit_points()
					  * (100+overseerUnit->skill.skill_potential*2) / 100;

		// ------ effect of god ----------//

		// ##### patch begin Gilbert 16/2 ######//
//		if( overseerUnit->race_id == RACE_CELTIC && nation_recno 
//			&& god_res[GOD_CELTIC]->nation_prayer_count(nation_recno) > 0 )
		if( nation_recno && god_res[GOD_CELTIC]->nation_prayer_count(nation_recno) > 0 )
		{
			if( overseerUnit->race_id == RACE_CELTIC )
				incValue += incValue / 2;		// 50% skill increase in fort
			else
				incValue += incValue / 5;		// 20% skill increase in fort
		}
		// ##### patch end Gilbert 16/2 ######//

		if( is_ai && config.ai_aggressiveness > OPTION_MODERATE )
			incValue += incValue * (config.ai_aggressiveness-OPTION_MODERATE) / 5;		// 20% faster if aggressivness is high, 40% faster if aggressiveness is very high

		overseerUnit->skill.inc_combat_level( (float)incValue/100 );
	}

	//------- increase the solider's combat level -------//

	for( int i=0 ; i<soldier_count ; i++ )
	{
		Soldier* soldierPtr = soldier_array + i;

		#ifdef DEBUG

		err_when( !soldierPtr->name_id );

		err_when( soldierPtr->is_monster() &&
					 monster_res.name_used_array[soldierPtr->name_id-1] < 1 );

		#endif

		if( soldierPtr->is_under_training() )		// skip unit under initial training
			continue;

		//------- increase soldier skill -----------//

		if( soldierPtr->combat_level() < overseerSkill
			&& soldierPtr->combat_level() < MAX_COMBAT_TRAIN )
		{
			incValue = max(20, overseerSkill - (int)soldierPtr->combat_level())
						  * soldierPtr->hit_points / soldierPtr->max_hit_points()
						  * (100+soldierPtr->skill.skill_potential*2+overseerUnit->item.ability(ITEM_ABILITY_TRAIN)) / 100;

			// ------ effect of god ----------//

			// ###### patch begin Gilbert 16/2 ######//
			//if( soldierPtr->race_id == RACE_CELTIC && nation_recno 
			//	&& god_res[GOD_CELTIC]->nation_prayer_count(nation_recno) > 0 )
			if( nation_recno 
				&& god_res[GOD_CELTIC]->nation_prayer_count(nation_recno) > 0 )
			{
				if( soldierPtr->race_id == RACE_CELTIC )
					incValue += incValue / 2;		// 50% skill increase in fort
				else
					incValue += incValue / 5;		// 20% skill increase in fort
			}
			// ###### patch end Gilbert 16/2 ######//

			// ###### patch begin Gilbert 23/12 #########//
			// penalty of egyptain
			if( soldierPtr->race_id == RACE_EGYPTIAN && nation_recno
				&& god_res[GOD_EGYPTIAN]->nation_prayer_count(nation_recno) > 0 )
			{
				incValue = incValue * (MAX_WORKER*2) / (MAX_WORKER*2+god_res[GOD_EGYPTIAN]->nation_prayer_count(nation_recno));
			}
			// ###### patch end Gilbert 23/12 #########//

			if( is_ai && config.ai_aggressiveness > OPTION_MODERATE )
				incValue += incValue * (config.ai_aggressiveness-OPTION_MODERATE) / 5;		// 20% faster if aggressivness is high, 40% faster if aggressiveness is very high

			soldierPtr->skill.inc_combat_level( (float)incValue/100 );
		}

		//-- if the soldier has leadership potential, he learns leadership --//

		if( soldierPtr->skill.skill_potential > 0
			 && soldierPtr->skill_level() < MAX_SKILL_TRAIN )
		{
			incValue = (int) max(50, overseerSkill-soldierPtr->skill_level())
						  * soldierPtr->hit_points / soldierPtr->max_hit_points()
						  * soldierPtr->skill.skill_potential*2 / 100;

			if( is_ai && config.ai_aggressiveness > OPTION_MODERATE )
				incValue += incValue * (config.ai_aggressiveness-OPTION_MODERATE) / 5;		// 20% faster if aggressivness is high, 40% faster if aggressiveness is very high

			soldierPtr->skill.inc_skill_level( (float)incValue/100 );
		}
	}
}
Exemplo n.º 21
0
/**
 * Updates soldier stats when
 * the soldier changes.
 */
void SoldierInfoState::init()
{
	if(_base->getSoldiers()->empty())
	{
		_game->popState();
		return;
	}
	if(_soldier == _base->getSoldiers()->size())
	{
		_soldier = 0;
	}
	Soldier *s = _base->getSoldiers()->at(_soldier);
	_edtSoldier->setText(s->getName());
	UnitStats *initial = s->getInitStats();
	UnitStats *current = s->getCurrentStats();

	SurfaceSet *texture = _game->getResourcePack()->getSurfaceSet("BASEBITS.PCK");
	texture->getFrame(s->getRankSprite())->setX(0);
	texture->getFrame(s->getRankSprite())->setY(0);
	texture->getFrame(s->getRankSprite())->blit(_rank);

	std::wstringstream ss;
	ss << current->tu;
	_numTimeUnits->setText(ss.str());
	_barTimeUnits->setMax(current->tu);
	_barTimeUnits->setValue(current->tu);
	_barTimeUnits->setValue2(initial->tu);

	std::wstringstream ss2;
	ss2 << current->stamina;
	_numStamina->setText(ss2.str());
	_barStamina->setMax(current->stamina);
	_barStamina->setValue(current->stamina);
	_barStamina->setValue2(initial->stamina);

	std::wstringstream ss3;
	ss3 << current->health;
	_numHealth->setText(ss3.str());
	_barHealth->setMax(current->health);
	_barHealth->setValue(current->health);
	_barHealth->setValue2(initial->health);

	std::wstringstream ss4;
	ss4 << current->bravery;
	_numBravery->setText(ss4.str());
	_barBravery->setMax(current->bravery);
	_barBravery->setValue(current->bravery);
	_barBravery->setValue2(initial->bravery);

	std::wstringstream ss5;
	ss5 << current->reactions;
	_numReactions->setText(ss5.str());
	_barReactions->setMax(current->reactions);
	_barReactions->setValue(current->reactions);
	_barReactions->setValue2(initial->reactions);

	std::wstringstream ss6;
	ss6 << current->firing;
	_numFiring->setText(ss6.str());
	_barFiring->setMax(current->firing);
	_barFiring->setValue(current->firing);
	_barFiring->setValue2(initial->firing);

	std::wstringstream ss7;
	ss7 << current->throwing;
	_numThrowing->setText(ss7.str());
	_barThrowing->setMax(current->throwing);
	_barThrowing->setValue(current->throwing);
	_barThrowing->setValue2(initial->throwing);

	std::wstringstream ss8;
	ss8 << current->strength;
	_numStrength->setText(ss8.str());
	_barStrength->setMax(current->strength);
	_barStrength->setValue(current->strength);
	_barStrength->setValue2(initial->strength);

	std::wstring wsArmor;
	std::string armorType = s->getArmor()->getType();
	if (armorType == "STR_NONE_UC")
	{
		wsArmor.reserve(15);
		wsArmor = tr("STR_ARMOR");
		wsArmor += L"> ";
		wsArmor += tr(armorType);
	}
	else
		wsArmor = tr(armorType);

	_btnArmor->setText(wsArmor);
//	_txtArmor->setText(tr(s->getArmor()->getType()));

	_btnSack->setVisible(!(s->getCraft() && s->getCraft()->getStatus() == "STR_OUT"));

	std::wstringstream ss9;
	ss9 << tr("STR_RANK_") << L'\x01' << tr(s->getRankString());
	_txtRank->setText(ss9.str());

	std::wstringstream ss10;
	ss10 << tr("STR_MISSIONS") << L'\x01' << s->getMissions();
	_txtMissions->setText(ss10.str());

	std::wstringstream ss11;
	ss11 << tr("STR_KILLS") << L'\x01' << s->getKills();
	_txtKills->setText(ss11.str());

	std::wstringstream ss12;
	ss12 << tr("STR_CRAFT_") << L'\x01';
	if (s->getCraft() == 0)
		ss12 << tr("STR_NONE_UC");
	else
		ss12 << s->getCraft()->getName(_game->getLanguage());
	_txtCraft->setText(ss12.str());

	if (s->getWoundRecovery() > 0)
	{
		std::wstringstream ss13;
		ss13 << tr("STR_WOUND_RECOVERY") << L'\x01' << tr("STR_DAY", s->getWoundRecovery());
		_txtRecovery->setText(ss13.str());
	}
	else
	{
		_txtRecovery->setText(L"");
	}

	_txtPsionic->setVisible(s->isInPsiTraining());

	if(current->psiSkill > 0)
	{
		std::wstringstream ss14;
		ss14 << current->psiStrength;
		_numPsiStrength->setText(ss14.str());
		_barPsiStrength->setMax(current->psiStrength);
		_barPsiStrength->setValue(current->psiStrength);
		_barPsiStrength->setValue2(initial->psiStrength);

		std::wstringstream ss15;
		ss15 << current->psiSkill;
		_numPsiSkill->setText(ss15.str());
		_barPsiSkill->setMax(current->psiSkill);
		_barPsiSkill->setValue(current->psiSkill);
		_barPsiSkill->setValue2(initial->psiSkill);

		_txtPsiStrength->setVisible(true);
		_numPsiStrength->setVisible(true);
		_barPsiStrength->setVisible(true);

		_txtPsiSkill->setVisible(true);
		_numPsiSkill->setVisible(true);
		_barPsiSkill->setVisible(true);
	}
	else
	{
		_txtPsiStrength->setVisible(false);
		_numPsiStrength->setVisible(false);
		_barPsiStrength->setVisible(false);

		_txtPsiSkill->setVisible(false);
		_numPsiSkill->setVisible(false);
		_barPsiSkill->setVisible(false);
	}
}
Exemplo n.º 22
0
/**
 * Draws a unit, using the drawing rules of the unit.
 * This function is called by Map, for each unit on the screen.
 */
void UnitSprite::draw()
{
	Surface *torso = 0, *legs = 0, *leftArm = 0, *rightArm = 0, *item = 0;

	// magic numbers
	const int maleTorso = 32, femaleTorso = 267, legsStand = 16, legsKneel = 24, die = 264;
	const int larmStand = 0, rarmStand = 8, rarm1H = 232, larm2H = 240, ramr2H = 248, rarmShoot = 256;
	const int legsWalk[8] = { 56, 56+24, 56+24*2, 56+24*3, 56+24*4, 56+24*5, 56+24*6, 56+24*7 };
	const int larmWalk[8] = { 40, 40+24, 40+24*2, 40+24*3, 40+24*4, 40+24*5, 40+24*6, 40+24*7 };
	const int rarmWalk[8] = { 48, 48+24, 48+24*2, 48+24*3, 48+24*4, 48+24*5, 48+24*6, 48+24*7 };
	const int yoffWalk[8] = {1, 0, -1, 0, 1, 0, -1, 0};
	const int offX[8] = { 8, 10, 7, 4, -9, -11, -7, -3 };
	const int offY[8] = { -6, -3, 0, 2, 0, -4, -7, -9 };
	const int offYKneel = 4;

	clear();
	Soldier *soldier = dynamic_cast<Soldier*>(_unit->getUnit());

	if (_unit->isOut())
	{
		// unit is drawn as an item
		return;
	}

	if (_unit->getStatus() == STATUS_FALLING)
	{
		torso = _unitSurface->getFrame(die + _unit->getFallingPhase());
		torso->blit(this);
		return;
	}

	if (soldier != 0 && soldier->getGender() == GENDER_FEMALE)
	{
		torso = _unitSurface->getFrame(femaleTorso + _unit->getDirection());
	}
	else
	{
		torso = _unitSurface->getFrame(maleTorso + _unit->getDirection());
	}

	// when walking, torso(fixed sprite) has to be animated up/down
	if (_unit->getStatus() == STATUS_WALKING)
	{
		torso->setY(yoffWalk[_unit->getWalkingPhase()]);
		legs = _unitSurface->getFrame(legsWalk[_unit->getDirection()] + _unit->getWalkingPhase());
		leftArm = _unitSurface->getFrame(larmWalk[_unit->getDirection()] + _unit->getWalkingPhase());
		rightArm = _unitSurface->getFrame(rarmWalk[_unit->getDirection()] + _unit->getWalkingPhase());
	}
	else
	{
		if (_unit->isKneeled())
		{
			legs = _unitSurface->getFrame(legsKneel + _unit->getDirection());
		}
		else
		{
			legs = _unitSurface->getFrame(legsStand + _unit->getDirection());
		}
		leftArm = _unitSurface->getFrame(larmStand + _unit->getDirection());
		rightArm = _unitSurface->getFrame(rarmStand + _unit->getDirection());
	}

	// holding an item
	if (_item)
	{
		// draw handob item
		if (_unit->getStatus() == STATUS_AIMING)
		{
			int dir = (_unit->getDirection() + 2)%8;
			item = _itemSurface->getFrame(_item->getRules()->getHandSprite() + dir);
			item->setX(offX[_unit->getDirection()]);
			item->setY(offY[_unit->getDirection()]);
		}
		else
		{
			item = _itemSurface->getFrame(_item->getRules()->getHandSprite() + _unit->getDirection());
			item->setX(0);
			item->setY(0);
		}

		// draw arms holding the item
		if (_item->getRules()->getTwoHanded())
		{
			leftArm = _unitSurface->getFrame(larm2H + _unit->getDirection());
			if (_unit->getStatus() == STATUS_AIMING)
			{
				rightArm = _unitSurface->getFrame(rarmShoot + _unit->getDirection());
			}
			else
			{
				rightArm = _unitSurface->getFrame(ramr2H + _unit->getDirection());
			}
		}
		else
		{
			rightArm = _unitSurface->getFrame(rarm1H + _unit->getDirection());
		}

		// the fixed arm(s) have to be animated up/down when walking
		if (_unit->getStatus() == STATUS_WALKING)
		{
			item->setY(yoffWalk[_unit->getWalkingPhase()]);
			rightArm->setY(yoffWalk[_unit->getWalkingPhase()]);
			if (_item->getRules()->getTwoHanded())
				leftArm->setY(yoffWalk[_unit->getWalkingPhase()]);
		}
	}

	// offset everything but legs when kneeled
	if (_unit->isKneeled())
	{
		leftArm->setY(offYKneel);
		rightArm->setY(offYKneel);
		torso->setY(offYKneel);
		item?item->setY(item->getY() + offYKneel):void();
	}
	else if (_unit->getStatus() != STATUS_WALKING)
	{
		leftArm->setY(0);
		rightArm->setY(0);
		torso->setY(0);
	}
	
	// blit order depends on unit direction
	switch (_unit->getDirection())
	{
	case 0: leftArm->blit(this); legs->blit(this); item?item->blit(this):void(); torso->blit(this); rightArm->blit(this); break;
	case 1: leftArm->blit(this); legs->blit(this); torso->blit(this); item?item->blit(this):void(); rightArm->blit(this); break;
	case 2: leftArm->blit(this); legs->blit(this); torso->blit(this); item?item->blit(this):void(); rightArm->blit(this); break;
	case 3: legs->blit(this); torso->blit(this); leftArm->blit(this); rightArm->blit(this); item?item->blit(this):void(); break;
	case 4: rightArm->blit(this); legs->blit(this); torso->blit(this); leftArm->blit(this); item?item->blit(this):void(); break;
	case 5: rightArm->blit(this); legs->blit(this); item?item->blit(this):void(); torso->blit(this); leftArm->blit(this); break;
	case 6: rightArm->blit(this); legs->blit(this); item?item->blit(this):void(); torso->blit(this); leftArm->blit(this); break;
	case 7: item?item->blit(this):void(); leftArm->blit(this); rightArm->blit(this); legs->blit(this); torso->blit(this); break;
	}
}
Exemplo n.º 23
0
int main(int argc, char * argv[])
{
	glewInit();
	glutInit(&argc, argv);
	glutInitWindowSize(1024, 512);
	glutInitWindowPosition(0, 0);
	glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE);

	//Initialize object's colors / values
	torus.color = vec3(1.0f, 0.1f, 0.0f);
	square.color1 = vec3(1.0, 1.0, 1.0);
	square2.color1 = vec3(0.95f, 0.1f, 0.7f);
	square2.color2 = vec3(1.0f, 1.0f, 0.0f);
	disc.color = vec3(0.1f, 0.5f, 1.0f);
	sphere.color = vec3(0.15f, 0.45f, 0.0f);
	sphere2.color = vec3(0.45f, 0.05f, 0.25f);
	cylinder.color = vec3(0.0f, 0.5f, 0.0f);
	arena.texID = 18;
	egg.texID = 20;
	star.texID = 22;
	magneton.texID = 25;
	haunter.texID = 26;
	frog.texID = 27;
	goldeen.texID = 76;
	rain2.color = vec3(0.4f, 0.4f, 1.0f);
	snow2.color = vec3(1.0f, 1.0f, 1.0f);
	fontfilename = "Pokemon.ttf";

	//Initialize the precipitation
	numParts = 300;
	partX = new float[numParts];
	partY = new float[numParts];
	partOffset = new float[numParts];
	for(int i=0; i<numParts; i++){
		partX[i] = (float)(rand() % 1200);
		partX[i] = (partX[i] - 600)/100;

		partY[i] = (float)(rand() % 1200);
		partY[i] = (partY[i] - 600)/100;
		partOffset[i] = (float)(rand() % 360 + 1);
	}
	sphere.lava = true;sphere2.lava = false; //Initialize sphere statuses

	window.window_handle = glutCreateWindow("Solar System");
	glutReshapeFunc(ReshapeFunc);
	glutCloseFunc(CloseFunc);
	
	glutMotionFunc(mouseMovement);
	glutPassiveMotionFunc(mouseMovement); //check for mouse movement
	glutKeyboardFunc(KeyboardFunc);
	glutSpecialFunc(SpecialFunc);
	glutTimerFunc(window.interval, TimerFunc, 0);
	
	glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION);
	
	//Initialize everything

	if (glewInit() != GLEW_OK)
	{
		cerr << "GLEW failed to initialize." << endl;
		return 0;
	}

	init_resources();
	glutDisplayFunc(DisplayFunc);

	if (!fbo.Initialize(glm::ivec2(512, 512), 1, true)){
		cerr << "Frame buffer failed to initialize." << endl;
		return 0;
	}

	sph1.color = vec3(1.0f, 0.85f, 0.0f);
	if (!sph1.Initialize(8,1.0f, "phong3.vert", "phong3.frag")){return 0;}
	enm.color = vec3(0.75f, 0.0f, 0.75f);
	if (!enm.Initialize(2,0.05f, "phong.vert", "phong.frag")){return 0;}
	usr.color = vec3(0.0f, 0.0f, 0.5f);
	if (!usr.Initialize(2,0.05f, "phong.vert", "phong.frag")){return 0;}
	//if (!sb.Initialize()){return 0;}
	//if (!coin.Initialize()){return 0;}
	//if (!stadium.Initialize(0)){return 0;}
	if (!skybox.Initialize(0, 5000, "basic_skybox_shader.vert", "basic_skybox_shader.frag")){return 0;}
	if (!skybox2.Initialize(1, 5025, "basic_skybox_shader.vert", "basic_skybox_shader.frag")){return 0;}
	if (!skybox3.Initialize(2, 5050, "basic_skybox_shader.vert", "basic_skybox_shader.frag")){return 0;}
	if (!skyboxUW.Initialize(3, 5075, "basic_skybox_shader.vert", "basic_skybox_shader.frag")){return 0;}


	arena.order = 1;
	
	if (!sphere.Initialize(15, 1, "sphereShader2.vert", "sphereShader2.frag")){return 0;}
	if (!sphere2.Initialize(15, 1, "sphereShader2.vert", "sphereShader2.frag")){return 0;}
	if (!rain2.Initialize(2, 0.02f, "phong.vert", "phong.frag")){return 0;}
	if (!snow2.Initialize(3, 0.02f, "phong.vert", "phong.frag")){return 0;}
	//if (!egg.Initialize(15, 1, "./textures/alienEgg.jpg", "basic_texture_shader.vert", "basic_texture_shader.frag")){return 0;}
	if (!square.Initialize(1, 3.0f, "phong.vert", "phong.frag")) {return 0;}
	if (!sq4.Initialize(1, 5.0f, "basic_texture_shader.vert", "basic_texture_shader.frag")) {return 0;}
	if (!disc.Initialize(8, 1.0f, "phong3.vert", "phong3.frag")) {return 0;}
	if (!healthBar.Initialize(2, 1.0f, 1.f, 1.f, "phong3.vert", "phong3.frag")) {return 0;}
	if (!soldier.Initialize()) {return 0;}
	if (!ss.Initialize()) {return 0;}

	userTeam.userTeam = true;
	if (!userTeam.Initialize()) {return 0;}
	if (!cpuTeam.Initialize()) {return 0;}

	glutMainLoop();
}
Exemplo n.º 24
0
/**
 * Update soldier stats when
 * the soldier changes.
 */
void SoldierInfoState::init()
{
	Soldier *s = _base->getSoldiers()->at(_soldier);
	_edtSoldier->setText(s->getName());
	UnitStats *initial = s->getInitStats();
	UnitStats *current = s->getCurrentStats();

	SurfaceSet *texture = _game->getResourcePack()->getSurfaceSet("BASEBITS.PCK");
	texture->getFrame(s->getRankSprite())->setX(0);
	texture->getFrame(s->getRankSprite())->setY(0);
	texture->getFrame(s->getRankSprite())->blit(_rank);

	std::wstringstream ss;
	ss << current->tu;
	_numTimeUnits->setText(ss.str());
	_barTimeUnits->setMax(current->tu);
	_barTimeUnits->setValue(current->tu);
	_barTimeUnits->setValue2(initial->tu);

	std::wstringstream ss2;
	ss2 << current->stamina;
	_numStamina->setText(ss2.str());
	_barStamina->setMax(current->stamina);
	_barStamina->setValue(current->stamina);
	_barStamina->setValue2(initial->stamina);

	std::wstringstream ss3;
	ss3 << current->health;
	_numHealth->setText(ss3.str());
	_barHealth->setMax(current->health);
	_barHealth->setValue(current->health);
	_barHealth->setValue2(initial->health);

	std::wstringstream ss4;
	ss4 << current->bravery;
	_numBravery->setText(ss4.str());
	_barBravery->setMax(current->bravery);
	_barBravery->setValue(current->bravery);
	_barBravery->setValue2(initial->bravery);

	std::wstringstream ss5;
	ss5 << current->reactions;
	_numReactions->setText(ss5.str());
	_barReactions->setMax(current->reactions);
	_barReactions->setValue(current->reactions);
	_barReactions->setValue2(initial->reactions);

	std::wstringstream ss6;
	ss6 << current->firing;
	_numFiring->setText(ss6.str());
	_barFiring->setMax(current->firing);
	_barFiring->setValue(current->firing);
	_barFiring->setValue2(initial->firing);

	std::wstringstream ss7;
	ss7 << current->throwing;
	_numThrowing->setText(ss7.str());
	_barThrowing->setMax(current->throwing);
	_barThrowing->setValue(current->throwing);
	_barThrowing->setValue2(initial->throwing);

	std::wstringstream ss8;
	ss8 << current->strength;
	_numStrength->setText(ss8.str());
	_barStrength->setMax(current->strength);
	_barStrength->setValue(current->strength);
	_barStrength->setValue2(initial->strength);

	_txtArmor->setText(_game->getLanguage()->getString(s->getArmor()->getType()));

	std::wstringstream ss9;
	ss9 << _game->getLanguage()->getString("STR_RANK_") << L'\x01' << _game->getLanguage()->getString(s->getRankString());
	_txtRank->setText(ss9.str());

	std::wstringstream ss10;
	ss10 << _game->getLanguage()->getString("STR_MISSIONS") << L'\x01' << s->getMissions();
	_txtMissions->setText(ss10.str());

	std::wstringstream ss11;
	ss11 << _game->getLanguage()->getString("STR_KILLS") << L'\x01' << s->getKills();
	_txtKills->setText(ss11.str());

	std::wstringstream ss12;
	ss12 << _game->getLanguage()->getString("STR_CRAFT_") << L'\x01';
	if (s->getCraft() == 0)
		ss12 << _game->getLanguage()->getString("STR_NONE_UC");
	else
		ss12 << s->getCraft()->getName(_game->getLanguage());
	_txtCraft->setText(ss12.str());

	if (s->getWoundRecovery() > 1)
	{
		std::wstringstream ss13;
		ss13 << _game->getLanguage()->getString("STR_WOUND_RECOVERY") << L'\x01' << s->getWoundRecovery();
		if (s->getWoundRecovery() > 1)
			ss13 << _game->getLanguage()->getString("STR_DAYS");
		else
			ss13 << _game->getLanguage()->getString("STR_DAY");
		_txtRecovery->setText(ss13.str());
	}
	else
	{
		_txtRecovery->setText(L"");
	}
}
Exemplo n.º 25
0
/**
 * Updates all soldier stats when the soldier changes.
 */
void InventoryState::init()
{
	State::init();
	BattleUnit *unit = _battleGame->getSelectedUnit();

	// no selected unit, close inventory
	if (unit == 0)
	{
		btnOkClick(0);
		return;
	}
	// skip to the first unit with inventory
	if (!unit->hasInventory())
	{
		if (_parent)
		{
			_parent->selectNextPlayerUnit(false, false, true);
		}
		else
		{
			_battleGame->selectNextPlayerUnit(false, false, true);
		}
		// no available unit, close inventory
		if (_battleGame->getSelectedUnit() == 0 || !_battleGame->getSelectedUnit()->hasInventory())
		{
			// starting a mission with just vehicles
			btnOkClick(0);
			return;
		}
		else
		{
			unit = _battleGame->getSelectedUnit();
		}
	}

	unit->setCache(0);
	_soldier->clear();
	_rank->clear();

	_txtName->setBig();
	_txtName->setText(unit->getName(_game->getLanguage()));
	_inv->setSelectedUnit(unit);
	Soldier *s = unit->getGeoscapeSoldier();
	if (s)
	{
		SurfaceSet *texture = _game->getMod()->getSurfaceSet("SMOKE.PCK");
		texture->getFrame(20 + s->getRank())->setX(0);
		texture->getFrame(20 + s->getRank())->setY(0);
		texture->getFrame(20 + s->getRank())->blit(_rank);

		std::string look = s->getArmor()->getSpriteInventory();
		if (s->getGender() == GENDER_MALE)
			look += "M";
		else
			look += "F";
		if (s->getLook() == LOOK_BLONDE)
			look += "0";
		if (s->getLook() == LOOK_BROWNHAIR)
			look += "1";
		if (s->getLook() == LOOK_ORIENTAL)
			look += "2";
		if (s->getLook() == LOOK_AFRICAN)
			look += "3";
		look += ".SPK";
		const std::set<std::string> &ufographContents = FileMap::getVFolderContents("UFOGRAPH");
		std::string lcaseLook = look;
		std::transform(lcaseLook.begin(), lcaseLook.end(), lcaseLook.begin(), tolower);
		if (ufographContents.find("lcaseLook") == ufographContents.end() && !_game->getMod()->getSurface(look))
		{
			look = s->getArmor()->getSpriteInventory() + ".SPK";
		}
		_game->getMod()->getSurface(look)->blit(_soldier);
	}
	else
	{
		Surface *armorSurface = _game->getMod()->getSurface(unit->getArmor()->getSpriteInventory());
		if (armorSurface)
		{
			armorSurface->blit(_soldier);
		}
	}

	updateStats();
	_refreshMouse();
}
Exemplo n.º 26
0
/**
 * Updates all soldier stats when the soldier changes.
 */
void InventoryState::init()
{
	BattleUnit *unit = _battleGame->getSelectedUnit();

	unit->setCache(0);
	_soldier->clear();
	_btnRank->clear();

	_txtName->setText(unit->getName(_game->getLanguage()));
	_inv->setSelectedUnit(unit);
	Soldier *s = _game->getSavedGame()->getSoldier(unit->getId());
	if (s)
	{
		SurfaceSet *texture = _game->getResourcePack()->getSurfaceSet("BASEBITS.PCK");
		texture->getFrame(s->getRankSprite())->setX(0);
		texture->getFrame(s->getRankSprite())->setY(0);
		texture->getFrame(s->getRankSprite())->blit(_btnRank);

		std::string look = s->getArmor()->getSpriteInventory();
		if (s->getGender() == GENDER_MALE)
			look += "M";
		else
			look += "F";
		if (s->getLook() == LOOK_BLONDE)
			look += "0";
		if (s->getLook() == LOOK_BROWNHAIR)
			look += "1";
		if (s->getLook() == LOOK_ORIENTAL)
			look += "2";
		if (s->getLook() == LOOK_AFRICAN)
			look += "3";
		look += ".SPK";
		if (!CrossPlatform::fileExists(CrossPlatform::getDataFile("UFOGRAPH/" + look)))
		{
			look = s->getArmor()->getSpriteInventory() + ".SPK";
		}
		_game->getResourcePack()->getSurface(look)->blit(_soldier);
	}
	if (_showMoreStatsInInventoryView && !_tu)
	{
		std::wstringstream ss2;
		ss2 << _game->getLanguage()->getString("STR_FACCURACY") << L'\x01' << (int)(unit->getStats()->firing * unit->getAccuracyModifier());
		_txtFAcc->setText(ss2.str());

		std::wstringstream ss3;
		ss3 << _game->getLanguage()->getString("STR_REACT") << L'\x01' << unit->getStats()->reactions;
		_txtReact->setText(ss3.str());

		if (unit->getStats()->psiSkill > 0)
		{
			std::wstringstream ss4;
			ss4 << _game->getLanguage()->getString("STR_PSKILL") << L'\x01' << unit->getStats()->psiSkill;
			_txtPSkill->setText(ss4.str());

			std::wstringstream ss5;
			ss5 << _game->getLanguage()->getString("STR_PSTRENGTH") << L'\x01' << unit->getStats()->psiStrength;
			_txtPStr->setText(ss5.str());
		}
		else
		{
			_txtPSkill->setText(L"");
			_txtPStr->setText(L"");
		}
	}
	updateStats();
}
Exemplo n.º 27
0
/**
 * Initializes all the elements in the Soldier Armor window.
 * @param game Pointer to the core game.
 * @param base Pointer to the base to get info from.
 * @param soldier ID of the selected soldier.
 */
SoldierArmorState::SoldierArmorState(Game *game, Base *base, size_t soldier) : State(game), _base(base), _soldier(soldier)
{
	_screen = false;

	// Create objects
	_window = new Window(this, 192, 120, 64, 40, POPUP_BOTH);
	_btnCancel = new TextButton(140, 16, 90, 136);
	_txtTitle = new Text(182, 9, 69, 48);
	_txtSoldier = new Text(182, 9, 69, 56);
	_txtType = new Text(90, 9, 80, 72);
	_txtQuantity = new Text(70, 9, 177, 72);
	_lstArmor = new TextList(160, 48, 73, 88);

	// Set palette
	_game->setPalette(_game->getResourcePack()->getPalette("BACKPALS.DAT")->getColors(Palette::blockOffset(4)), Palette::backPos, 16);

	add(_window);
	add(_btnCancel);
	add(_txtTitle);
	add(_txtSoldier);
	add(_txtType);
	add(_txtQuantity);
	add(_lstArmor);

	centerAllSurfaces();

	// Set up objects
	_window->setColor(Palette::blockOffset(13)+10);
	_window->setBackground(_game->getResourcePack()->getSurface("BACK14.SCR"));

	_btnCancel->setColor(Palette::blockOffset(13)+5);
	_btnCancel->setText(_game->getLanguage()->getString("STR_CANCEL_UC"));
	_btnCancel->onMouseClick((ActionHandler)&SoldierArmorState::btnCancelClick);
	_btnCancel->onKeyboardPress((ActionHandler)&SoldierArmorState::btnCancelClick, (SDLKey)Options::getInt("keyCancel"));

	_txtTitle->setColor(Palette::blockOffset(13)+5);
	_txtTitle->setAlign(ALIGN_CENTER);
	_txtTitle->setText(_game->getLanguage()->getString("STR_SELECT_ARMOR_FOR"));

	_txtSoldier->setColor(Palette::blockOffset(13)+5);
	_txtSoldier->setAlign(ALIGN_CENTER);
	Soldier *s = _base->getSoldiers()->at(_soldier);
	_txtSoldier->setText(s->getName());

	_txtType->setColor(Palette::blockOffset(13)+5);
	_txtType->setText(_game->getLanguage()->getString("STR_TYPE"));

	_txtQuantity->setColor(Palette::blockOffset(13)+5);
	_txtQuantity->setText(_game->getLanguage()->getString("STR_QUANTITY_UC"));

	_lstArmor->setColor(Palette::blockOffset(13));
	_lstArmor->setArrowColor(Palette::blockOffset(13)+5);
	_lstArmor->setColumns(2, 112, 41);
	_lstArmor->setSelectable(true);
	_lstArmor->setBackground(_window);
	_lstArmor->setMargin(8);

	const std::vector<std::string> &armors = _game->getRuleset()->getArmorsList();
	for (std::vector<std::string>::const_iterator i = armors.begin(); i != armors.end(); ++i)
	{
		Armor *a = _game->getRuleset()->getArmor(*i);
		if (_base->getItems()->getItem(a->getStoreItem()) > 0)
		{
			_armors.push_back(a);
			std::wstringstream ss;
			ss << _base->getItems()->getItem(a->getStoreItem());
			_lstArmor->addRow(2, _game->getLanguage()->getString(a->getType()).c_str(), ss.str().c_str());
		}
		else if (a->getStoreItem() == "STR_NONE")
		{
			_armors.push_back(a);
			_lstArmor->addRow(1, _game->getLanguage()->getString(a->getType()).c_str());
		}
	}
	_lstArmor->onMouseClick((ActionHandler)&SoldierArmorState::lstArmorClick);
}
void
GameSession::init()
{
  loops = 0;
  deltas = 0.0;

  start_time = CL_System::get_time ();
  frames = 0;

  collision_mgr       = new CollisionManager();
  buildingtypemanager = new BuildingTypeManager();

  // Load helper functions
  // FIXME: These functions need a better place
  scm_c_primitive_load(path_manager.complete("feuerkraft.scm").c_str());
  scm_c_primitive_load(path_manager.complete("input.scm").c_str());
  
  // Deserialize the game world
  {
    std::cout << "<<<<<<<<<<<<< Parsing map <<<<<<<<<<<<<" << std::endl;
    SCM fdes = scm_open_file (scm_makfrom0str(filename.c_str()), 
                              scm_makfrom0str("r"));
    SCM lst = scm_read (fdes);
    scm_close (fdes);

    // unstable Testing stuff
    //OutputWorldBuilder builder;
    //SexprWorldReader(lst, &builder).run();

    // Now we create the real world
    world = new GameWorld(lst);
    std::cout << ">>>>>>>>>>>>> Parsing map >>>>>>>>>>>>>" << std::endl;
  }
  // End: Test of parsing code

  // The all mighty soldier that the player controlls
  Soldier* soldier = new Soldier(AList());
  soldier->set_position(FloatVector2d (500, 1100));

  {
    Soldier* soldier = new Soldier(AList());
    soldier->set_position(FloatVector2d (1400, 1500));
    SoldierAI* ai = new SoldierAI(soldier);
    world->add(soldier);
    AIManager::instance()->add(ai);
  }

  {
    Soldier* soldier = new Soldier(AList());
    soldier->set_position(FloatVector2d (1300, 1600));
    SoldierAI* ai = new SoldierAI(soldier);
    world->add(soldier);
    AIManager::instance()->add(ai);
  }

  world->add(new RobotTank(660, 1245, 0, 100.0f));
  world->add(new Helicopter(AList()
                            .set_float("x-pos", 600)
                            .set_float("y-pos", 1245)
                            .set_int("type", 0)));
  world->add(new Helicopter(AList()
                            .set_float("x-pos", 600)
                            .set_float("y-pos", 1445)
                            .set_int("type", 1)));
  world->add(new Helicopter(AList()
                            .set_float("x-pos", 660)
                            .set_float("y-pos", 1645)
                            .set_int("type", 2)));

  world->add(new Tank(FloatVector2d (650, 1245), 5, "feuerkraft/tank", "feuerkraft/turret", "feuerkraft/fire2"));
  world->add(new Tank(FloatVector2d (750, 1245), 5, "feuerkraft/tank", "feuerkraft/turret", "feuerkraft/fire2"));
  world->add(new Tank(FloatVector2d (850, 1245), 5, "feuerkraft/tank", "feuerkraft/turret", "feuerkraft/fire2"));

  {
    Tank* tank = new Tank(FloatVector2d (450, 1245), 5, "feuerkraft/tank", "feuerkraft/turret", "feuerkraft/fire2");
    world->add(tank);
    AIManager::instance()->add(new VehicleRoboAI(tank));
  }

  {
    Tank* tank = new Tank(FloatVector2d (0, 1245), 5, "feuerkraft/tank2", "feuerkraft/turret", "feuerkraft/fire2");
    world->add(tank);
    AIManager::instance()->add(new VehicleRoboAI(tank));
  }

  {
    Tank* tank = new Tank(FloatVector2d (-100, 1245), 5, "feuerkraft/tank", "feuerkraft/turret2", "feuerkraft/fire2");
    world->add(tank);
    AIManager::instance()->add(new VehicleRoboAI(tank));
  }

  {
    Tank* tank = new Tank(FloatVector2d (560, 1245), 5, "feuerkraft/tank2", "feuerkraft/turret2", "feuerkraft/fire2");
    world->add(tank);
    VehiclePathAI* ai = new VehiclePathAI(tank);

    ai->drive_to(FloatVector2d(200, 200));
    ai->drive_to(FloatVector2d(500, 200));
    ai->drive_to(FloatVector2d(500, 500));
    ai->drive_to(FloatVector2d(1500, 500));
    ai->drive_to(FloatVector2d(1500, 300));

    AIManager::instance()->add(ai);
  }

  world->add(new Background (resources->get_sprite("feuerkraft/sand"), -10.0f));
  world->add(soldier);

  player = new Player(soldier);
  view   = new View(0, 0, CL_Display::get_width(), CL_Display::get_height(), new PlayerViewUpdater(player));
  DisplayManager::init();
}
Exemplo n.º 29
0
/**
 * Returns to the previous screen.
 * @param action Pointer to an action.
 */
void MonthlyReportState::btnOkClick(Action *)
{
	if (!_gameOver)
	{
		_game->popState();
		// Award medals for service time
		// Iterate through all your bases
		for (std::vector<Base*>::iterator b = _game->getSavedGame()->getBases()->begin(); b != _game->getSavedGame()->getBases()->end(); ++b)
		{
			// Iterate through all your soldiers
			for (std::vector<Soldier*>::iterator s = (*b)->getSoldiers()->begin(); s != (*b)->getSoldiers()->end(); ++s)
			{
				Soldier *soldier = _game->getSavedGame()->getSoldier((*s)->getId());
				// Award medals to eligible soldiers
				soldier->getDiary()->addMonthlyService();
				if (soldier->getDiary()->manageCommendations(_game->getMod()))
				{
					_soldiersMedalled.push_back(soldier);
				}
			}
		}
		if (!_soldiersMedalled.empty())
		{
			_game->pushState(new CommendationState(_soldiersMedalled));
		}

		bool training = false;
		bool psi = false;
		for (std::vector<Base*>::const_iterator b = _game->getSavedGame()->getBases()->begin(); b != _game->getSavedGame()->getBases()->end(); ++b)
		{
			psi = psi || (*b)->getAvailablePsiLabs();
			training = training || (*b)->getAvailableTraining();
		}
		if (!Options::anytimePsiTraining)
		{
			if (psi)
			{
				_game->pushState(new PsiTrainingState);
			}
			else if (training)
			{
				_game->pushState(new TrainingState);
			}
		}
		// Autosave
		if (_game->getSavedGame()->isIronman())
		{
			_game->pushState(new SaveGameState(OPT_GEOSCAPE, SAVE_IRONMAN, _palette));
		}
		else if (Options::autosave)
		{
			_game->pushState(new SaveGameState(OPT_GEOSCAPE, SAVE_AUTO_GEOSCAPE, _palette));
		}
	}
	else
	{
		if (_txtFailure->getVisible())
		{
			_game->pushState(new CutsceneState("loseGame"));
		}
		else
		{
			_window->setColor(_game->getMod()->getInterface("monthlyReport")->getElement("window")->color2);
			_txtTitle->setVisible(false);
			_txtMonth->setVisible(false);
			_txtRating->setVisible(false);
			_txtIncome->setVisible(false);
			_txtMaintenance->setVisible(false);
			_txtBalance->setVisible(false);
			_txtDesc->setVisible(false);
			_btnOk->setVisible(false);
			_btnBigOk->setVisible(true);
			_txtFailure->setVisible(true);
			_game->getMod()->playMusic("GMLOSE");
		}
	}
}
Exemplo n.º 30
0
void Soldier::copy(const Soldier& otherSoldier) {
	setName(otherSoldier.getName());
	setAge(otherSoldier.getAge());
	setSkillpoints(otherSoldier.getSkillpoints());
	setSalary(otherSoldier.getSalary());
}