Ejemplo n.º 1
0
void Creature::loadProperties(const Aurora::GFF3Struct &gff) {
	// Tag
	_tag = gff.getString("Tag", _tag);

	// Name

	Aurora::LocString firstName;
	gff.getLocString("FirstName", firstName);
	Aurora::LocString lastName;
	gff.getLocString("LastName", lastName);

	if (!firstName.empty()) {
		_name = firstName.getString();
		if (!lastName.empty())
			_name += " " + lastName.getString();
	}


	// Description
	_description = gff.getString("Description", _description);

	// Portrait
	loadPortrait(gff);

	// Equipment
	loadEquipment(gff);

	// Appearance
	_appearance = gff.getUint("Appearance_Type", _appearance);

	// Static
	_static = gff.getBool("Static", _static);

	// Usable
	_usable = gff.getBool("Useable", _usable);

	// PC
	_isPC = gff.getBool("IsPC", _isPC);

	// Gender
	_gender = Gender(gff.getUint("Gender"));

	// Race
	_race = Race(gff.getSint("Race", _race));
	_subRace = SubRace(gff.getSint("SubraceIndex", _subRace));

	// Hit Points
	_currentHitPoints = gff.getSint("CurrentHitPoints", _maxHitPoints);
	_maxHitPoints = gff.getSint("MaxHitPoints", _currentHitPoints);

	_minOneHitPoint = gff.getBool("Min1HP", _minOneHitPoint);

	// Faction
	_faction = Faction(gff.getUint("FactionID"));

	// Scripts
	readScripts(gff);

	_conversation = gff.getString("Conversation", _conversation);
}
Ejemplo n.º 2
0
 Race Races::getRace(std::string &name)
 {
   for (int i = 0; i < Races::Enum::MAX; ++i )
   {
     if ( name == RaceInternal::raceNames[i] )
       return Race(i);
   }
   return Races::Unknown;
 }
Ejemplo n.º 3
0
int Hex::GetPinnage(const Team& team) const
{
    int nPinnage = 0;
    for (auto& fleet : m_fleets)
    {
        if (fleet.FindSquadron(ShipType::GCDS))
            return 1000;
        if (!(Race(team.GetRace()).IsAncientsAlly() && fleet.GetColour() == Colour::None))
            nPinnage += (fleet.GetColour() == team.GetColour() ? -1 : 1) * fleet.GetShipCount();
    }
    return nPinnage;
}
Ejemplo n.º 4
0
bool Hex::HasPendingBattle(const Game& game) const
{
    if (IsOwned() && HasForeignShip(m_colour) && HasPopulation())
        return true;

    if (m_fleets.size() < 2)
        return false;

    if (m_fleets.size() == 2)
        if (HasShip(Colour::None, ShipType::Ancient))
            if (Race(game.GetTeam(m_fleets.back().GetColour()).GetRace()).IsAncientsAlly())
                return false;
    return true;
}
Ejemplo n.º 5
0
void Race::read_races_txt() {
    std::ifstream file("races_list.txt");
    std::string line;

    if (!file.is_open()) {
        std::cout << "Unable to open race-list.txt!" << std::endl;
        log_file << "Unable to open race-list.txt!" << std::endl;
        return;
    }

    Race temp_race;
    while (std::getline(file, line)) {
        if (line.front() == '#') continue;  //comment line
        if (line.find_first_not_of(" \n\t\r") == std::string::npos) continue;   //if line is empty
        while (line.find(";") == std::string::npos) {   //line ends with semicolon
            std::string buffer_line = "";
            std::getline(file, buffer_line);
            line += buffer_line;
        }
        line.erase(line.find(";"));
        trimr_string(line); //erasing unnecessary from end
        if (line == "NEW_RACE") {
            temp_race = {};
        } else if (line == "PUSH_RACE") {
            RACES_LIST.insert({temp_race.name, Race(temp_race)});
            log_file << "Added new item to RACES_LIST: " << temp_race.name << std::endl;
            temp_race = {};
        } else if (line.find("name") != std::string::npos) {
            line.erase(0, line.find("=") + 1);
            triml_string(line);
            temp_race.name = line;
        } else if (line.find("min_body_size") != std::string::npos) {
            line.erase(0, line.find("=") + 1);
            triml_string(line);
            temp_race.min_body_size = std::stoi(line);
        } else if (line.find("max_body_size") != std::string::npos) {
            line.erase(0, line.find("=") + 1);
            triml_string(line);
            temp_race.max_body_size = std::stoi(line);
        } else if (line.find("body") != std::string::npos) {
            line.erase(0, line.find("=") + 1);
            triml_string(line);
            for (auto& it : split_with_match_chars(line)) {
                Bodypart bpart(it);
                temp_race.bodymap.insert({bpart.get_name(), bpart});
            }
        }
    }
}
Ejemplo n.º 6
0
Cmd::ProcessResult TradeCmd::Process(const Input::CmdMessage& msg, CommitSession& session)
{
	const Team& team = session.GetGame().GetTeam(m_colour);
	auto& storage = team.GetStorage();

	auto& m = VerifyCastInput<const Input::CmdTrade>(msg);

	const int fromCount = m.m_count * Race(team.GetRace()).GetTradeRate();
	VERIFY_INPUT_MSG("no count", m.m_count > 0);
	VERIFY_INPUT_MSG("to == from", m.m_from != m.m_to);
	VERIFY_INPUT_MSG("can't afford trade", fromCount <= storage[m.m_from]);

	TradeRecord::PairVec srcs{ { m.m_from, fromCount } };
	TradeRecord::Pair dst(m.m_to, m.m_count);

	TradeRecord* pRec = new TradeRecord(m_colour, srcs, dst);
	DoRecord(RecordPtr(pRec), session);

	return nullptr;
}
Ejemplo n.º 7
0
//打印单元信息
void PrintUnit( Unit* p ){
	printf("[%s,%s,%s] %.0f (%.0f,%.0f,%.0f)\n",
			ansi(p->sName).c_str(),Race(p->iRace),Class(p->iClass),
			sqrt(p->distance),p->pos[0],p->pos[1],p->pos[2] );
	printf("	lv%d hp%d/%d mp%d/%d ",
			p->iLevel,p->iHealth,p->iMaxHealth,p->iMana,p->iMaxMana );
	if( p->sTarget.empty() )
		printf("TARGET[None] ");
	else
		printf("TARGET[%s] ",ansi(p->sTarget).c_str() );
	printf("CA[%s]\n",p->bCanAttack?"Yes":"No");
	printf("	CASTING[%s] %f - %f\n",ansi(p->sSpell).c_str(),p->SpellBegin,p->SpellEnd );
	printf("	BUFF:");
	for( int i = 0;i < p->iBuff;i++ ){
		printf("%s,%d,%f->%f|",ansi(p->Buff[i].name).c_str(),p->Buff[i].count,p->Buff[i].timeLeft,p->Buff[i].duration );
	}
	printf("\n	DEBUFF:");
	for( i = 0;i < p->iDebuff;i++ ){
		printf("%s,%d,%f->%f|",ansi(p->Debuff[i].name).c_str(),p->Debuff[i].count,p->Debuff[i].timeLeft,p->Debuff[i].duration );
	}
	printf("\n");
}
Ejemplo n.º 8
0
void Player::Go(Player *P, int numplayers, const Boundary &Path, const Boundary &BLL,const Boundary &BL,const Boundary &BR,const Boundary &BRR, const Button &B, Hook h[],int numHooks)
{
	if(B.reset)
	{
		Reset();
	}

	if(caught)
	{
		Hook myHookobj = *myHook;

		y = myHookobj.getY();
		caught = myHookobj.caughtOrNot();
		
		if(!caught)
		{
			y = .5;
			z += myHookobj.getRadius()+2;
		}

	}
	else
	{
			//Does everything for the player
		//Works for every type of player. no specifications need to be given, just a lot of objects get passed in

		Input(B);//Keyboard input for all players

		//Player-Player interaction
		if(!finish)//The player hasn't finished
		{
			Race(Path);//Follow the path
			AI(P,numplayers);//Act
		}
		else
			Finished();		//Act finished
		Bounce(P,numplayers);	//Check for bounces between each player

		//Player-Env. Interaction
		DetectBoundary(BLL,BL);	//Check left boundary
		DetectBoundary(BR,BRR);	//Check right boundary
		DetectEndCond(Path);	//Check end line&beginning


	
		if(usedtobeinabound==1||inabound==1)
			MoveBound();
		else//if not in a boundary
			MoveDamp();
	
		//Combine all
		Move();
	
		//Check to see that the Players have not exicted the outer boundary
		Check(BLL, BL,Path,BR, BRR);
		CheckFinished(Path);//Check to see if the player is passed the ifinish line
		if(pt == 0)
		{
			CheckCollision(h, numHooks);
		}

	}
}
Ejemplo n.º 9
0
long Player::ParseTalkTokens(char *write_buffer, char *input_buffer)
{
    char *profession[] =
    {
        "Warrior",
        "Trader",
        "Explorer"
    };
    char *race[] =
    {
        "Terran",
        "Jenquai",
        "Progen"
    };
	char *aprofession[] =
	{
		"a Warrior",
		"a Trader",
		"an Explorer"
	};

	char *ptr = write_buffer;
	char *token_ptr;

	long length = 0;
	//scan text for flags
	token_ptr = strchr(input_buffer, '@');

	if (token_ptr)
	{
		char *tree_ptr = input_buffer;
		while (*tree_ptr != 0)
		{
			if (*tree_ptr == '@')
			{
				token_ptr = tree_ptr+1;
				switch (token_ptr[0])
				{
				case 'a': //a[n] @profession
					if (strncmp(token_ptr, "aprofession", 11) == 0)
					{
						strcpy(ptr, aprofession[Profession()]);
						ptr += strlen(aprofession[Profession()]);
						tree_ptr += 11;
					}
					break;
				case 'c': //class (== profession)
					if (token_ptr[1] == 'l' && token_ptr[2] == 'a' && token_ptr[3] == 's' &&
						token_ptr[1] == 's')
					{
						strcpy(ptr, profession[Profession()]);
						ptr += strlen(profession[Profession()]);
						tree_ptr += 10;
					}
					break;
				case 'n': //name
					if (token_ptr[1] == 'a' && token_ptr[2] == 'm' && token_ptr[3] == 'e')
					{
						strcpy(ptr, Name());
						ptr += strlen(Name());
						tree_ptr += 4;
					}
					break;
				case 'r': //race
					if (token_ptr[1] == 'a' && token_ptr[2] == 'c' && token_ptr[3] == 'e')
					{
						strcpy(ptr, race[Race()]);
						ptr += strlen(race[Race()]);
						tree_ptr += 4;
					}
					break;
				case 'p':
					if (strncmp(token_ptr, "profession", 10) == 0)
					{
						strcpy(ptr, profession[Profession()]);
						ptr += strlen(profession[Profession()]);
						tree_ptr += 10;
					}
					break;
				default:
					*ptr++ = *tree_ptr;
					break;
				}
			}
			else
			{
				*ptr++ = *tree_ptr;
			}
			tree_ptr++;
		}
	}
	else
	{
		strcpy(ptr, input_buffer);
		ptr += strlen(input_buffer);
	}

	length = (long) (ptr - write_buffer);

	return length;
}
Ejemplo n.º 10
0
void EventGraphDisplay::addRaceArc(int race_id, const VarsInfo::RaceInfo& race, const char* color) {
	m_raceArcs.push_back(Race(race_id, race, color));
}
Ejemplo n.º 11
0
bool City::load_data(std::istream& data)
{
  clear_data();

  data >> uid;
  std::string tmpstr;
  while (tmpstr != "!") {
    data >> tmpstr;
    if (tmpstr != "!") {
      if (!name.empty()) {
        name = name + " ";
      }
      name = name + tmpstr;
    }
  }
  int tmptype, tmprace;
  data >> tmptype >> tmprace;
  if (tmptype >= CITY_TYPE_MAX || tmptype <= 0) {
    debugmsg("City '%s' has type value of %d (range is 1 - %d)!",
             name.c_str(), tmptype, CITY_TYPE_MAX - 1);
    return false;
  }
  if (tmprace >= RACE_MAX || tmptype <= 0) {
    debugmsg("City '%s' has race value of %d (range is 1 - %d)!",
             name.c_str(), tmprace, RACE_MAX - 1);
    return false;
  }
  type = City_type(tmptype);
  race = Race(tmprace);

  data >> location.x >> location.y;

  if (!map.load_data(data)) {
    debugmsg("City '%s' failed to load map.", name.c_str());
    return false;
  }

  int num_routes;
  data >> num_routes;
  for (int i = 0; i < num_routes; i++) {
    int tmpuid;
    Trade_route tmproute;
    data >> tmpuid;
    if (!tmproute.load_data(data)) {
      debugmsg("City '%s' failed to load trade route to City %d.",
               name.c_str(), tmpuid);
      return false;
    }
    trade_routes[tmpuid] = tmproute;
  }

  for (int i = 0; i < CIT_MAX; i++) {
    if (!population[i].load_data(data)) {
      debugmsg("City '%s' failed to load %s data.",
               name.c_str(), citizen_type_name(Citizen_type(i), true).c_str());
      return false;
    }
  }

  for (int i = 0; i < RES_MAX; i++) {
    data >> resources[i];
  }

  for (int i = 0; i < MINERAL_MAX; i++) {
    data >> minerals[i];
  }

  int num_animals;
  data >> num_animals;
  for (int i = 0; i < num_animals; i++) {
    int tmpanimal, tmpnum;
    data >> tmpanimal >> tmpnum;
    if (tmpanimal <= 0 || tmpanimal >= ANIMAL_MAX) {
      debugmsg("City '%s' had animal of index %d (Range is 1 to %d)",
               name.c_str(), tmpanimal, ANIMAL_MAX - 1);
      return false;
    }
    livestock[ Animal(tmpanimal) ] = tmpnum;
  }

  return true;
}
Ejemplo n.º 12
0
void Player::ShipDamage(long source_id, float weapon_damage, short type)
{
	bool Ignored = false, OnDamage = false;

	if (!m_ObjectMgr)
	{
		return;
	}

    Object *obj = m_ObjectMgr->GetObjectFromID(source_id);
    if (obj && !DebugPlayer())
    {
		float TakeDamage = 0;
		float DamageAbsorbed = 0;

        //terminate warp, prospecting
        //TerminateWarp();						// This should only be done for hull damage
        AbortProspecting(true, false);

		if (m_DamageAbsorb > 0)
		{
			TakeDamage = m_DamageAbsorb - weapon_damage;
			if (TakeDamage < 0)
			{
				// Take damage when we run out of absorb
				m_DamageAbsorb = 0;
				TakeDamage *= -1;
				// Calculate the damage absorbed by the shield
				DamageAbsorbed -= (weapon_damage - TakeDamage);
			}
			else
			{
				// We take no damage because of the shield
				TakeDamage = 0;
				m_DamageAbsorb -= weapon_damage;
				// Calculate the damage absorbed by the shield
				DamageAbsorbed -= weapon_damage;
			}
		}
		else
		{
			// No shield take all damage
			TakeDamage = weapon_damage;
		}

		// TODO: Add code to reduce damage from buffs and deflects

		/*****************
		* Damage reduction section.
		******************/
		float redux_percent;
		float BeforeDamage = TakeDamage;
		switch(type)
		{
		case DAMAGE_IMPACT:
			//is this needed?
			redux_percent = m_Stats.GetStat(STAT_IMPACT_DEFLECT);
			TakeDamage *= (1.0f - (redux_percent > 0.5f ? 0.5f : redux_percent));
			break;
		case DAMAGE_EXPLOSIVE:
			redux_percent = m_Stats.GetStat(STAT_EXPLOSIVE_DEFLECT);
			TakeDamage *= (1.0f - (redux_percent > 0.5f ? 0.5f : redux_percent));
			break;
		case DAMAGE_PLASMA:
			redux_percent = m_Stats.GetStat(STAT_PLASMA_DEFLECT);
			TakeDamage *= (1.0f - (redux_percent > 0.5f ? 0.5f : redux_percent));
			break;
		case DAMAGE_ENERGY:
			redux_percent = m_Stats.GetStat(STAT_ENERGY_DEFLECT);
			TakeDamage *= (1.0f - (redux_percent > 0.5f ? 0.5f : redux_percent));
			break;
		case DAMAGE_EMP:
			redux_percent = m_Stats.GetStat(STAT_EMP_DEFLECT);
			TakeDamage *= (1.0f - (redux_percent > 0.5f ? 0.5f : redux_percent));
			break;
		case DAMAGE_CHEMICAL:
			redux_percent = m_Stats.GetStat(STAT_CHEM_DEFLECT);
			TakeDamage *= (1.0f - (redux_percent > 0.5f ? 0.5f : redux_percent));
			break;
		}

		// Find out if we absorbed any damage with the deflects
		DamageAbsorbed -= (BeforeDamage - TakeDamage);

        SendClientDamage(GameID(), source_id, TakeDamage, DamageAbsorbed, type, 1);

        bool send_shield_hit = GetShieldValue() >= TakeDamage ? true : false;
        if (send_shield_hit)
        {
            m_Mutex.Lock();

			Player *p = (0);
			
			while (g_PlayerMgr->GetNextPlayerOnList(p, m_RangeList))
			{
                p->SendObjectToObjectLinkedEffect(this, obj, 0x0021, 0x0003);
            }

            m_Mutex.Unlock();
        }

        //DB: Note - Shake does not occur on first hit
        //Shake stops when you run out of shields as it expects hull to decrease then
        ShipIndex()->Shake.SetDamage(TakeDamage);

        float shield_level = GetShieldValue();
		float dmg_reduce_percent = 0;

		if(m_CurrentSkill && m_CurrentSkill->SkillInterruptable(&Ignored, &OnDamage, &Ignored))
		{
			if(OnDamage)
			{
				m_CurrentSkill->InterruptSkillOnDamage(TakeDamage);
			}
		}

        if (TakeDamage > shield_level)
        {
            float hull_dmg = TakeDamage - shield_level;
            if (shield_level > 0.0f)
            {
                RemoveShield(shield_level);
            }

			//if dmg type is chemical, do bonus dmg to hull
			if(type == DAMAGE_CHEMICAL)
			{
				hull_dmg *= 1.2f; //20% bonus damage
			}

			//calculate in damage control, TW/PW only
			//Note: This is normal %, if you want the "effective percent" (like Turbo uses) you need to change this.
			if ( (Profession() == PROFESSION_WARRIOR && Race() == RACE_PROGEN) || 
				(Profession() == PROFESSION_WARRIOR && Race() == RACE_TERRAN) )
			{
				dmg_reduce_percent = 1.0f - m_Stats.GetStat(STAT_DAMAGE_CONTROL);
				if(dmg_reduce_percent < 0)
				{
					dmg_reduce_percent = 0;
				}
				hull_dmg = hull_dmg * dmg_reduce_percent;
			}

			//if dmg type is EMP, take no damage to hull (EMP can't hurt the hull)
			if(type == DAMAGE_EMP)
			{
				hull_dmg = 0;
			}

            RemoveHull(hull_dmg, obj);
			TerminateWarp();
        }
        else
        {
			//bonus damage for plasma
			if(type == DAMAGE_PLASMA)
			{
				TakeDamage *= 1.2f; //20% bonus damage
			}
            RemoveShield(TakeDamage);
        }
    }
}
Ejemplo n.º 13
0
void Game::generate_kingdoms()
{
  if (!world) {
    debugmsg("Game::generate_kingdoms() called with NULL world!");
    return;
  }

  if (!kingdoms.empty()) {
    for (int i = 0; i < kingdoms.size(); i++) {
      delete (kingdoms[i]);
    }
  }
  kingdoms.clear();

  bool color_free[c_null];  // c_null is the last color
  for (int i = 0; i < c_null; i++) {
    color_free[i] = true;
  }
// One kingdom for each race.  Start at 1 to skip RACE_NULL.
  for (int i = 1; i < RACE_MAX; i++) {
    popup_nowait("Initializing kingdoms (%d of %d)...", i, RACE_MAX - 1);

    Kingdom* kingdom = new Kingdom;
    kingdom->uid = i - 1;
    kingdom->set_game(this);
    kingdom->race = Race(i);
    Race_datum* race_dat = Race_data[i];
// Pick a color - try the official race color first
    if (race_dat->color < c_dkgray && color_free[ race_dat->color ]) {
      kingdom->color = race_dat->color;
      color_free[ race_dat->color ] = false;

    } else {
      std::vector<nc_color> colors = race_dat->kingdom_colors;
// Remove any already-used colors
      for (int i = 0; i < colors.size(); i++) {
        if (!color_free[ colors[i] ]) {
          colors.erase(colors.begin() + i);
          i--;
        }
      }
      if (colors.empty()) { // Can't use official colors; use a random one
        std::vector<nc_color> free_colors;
// Start at 1 to skip c_black; stop at c_dkgray to skip bright colors
        for (int i = 1; i < c_dkgray; i++) {
          if (color_free[i]) {
            free_colors.push_back( nc_color(i) );
          }
        }
        if (free_colors.empty()) {  // 8 kingdoms used already!
          kingdom->color = nc_color( rng(1, c_dkgray - 1) );
        } else {
          int index = rng(0, free_colors.size() - 1);
          kingdom->color = free_colors[index];
          color_free[ free_colors[index] ] = false;
        }
      } else {  // We can use an official color!
        int index = rng(0, colors.size() - 1);
        kingdom->color = colors[index];
        color_free[ colors[index] ] = false;
      }
    } // if (!color_free[race_dat->color])

// Place the kingdom.
    if (kingdom->place_capital(world)) {
      kingdoms.push_back( kingdom );  // ...and add to our list.
    }
  } // for (int i = 1; i < RACE_MAX; i++)

/* Now, expand the kingdoms by placing duchy seats.  To keep things fair, each
 * kingdom gets to place a single city/duchy at a time.  We go through our list,
 * each kingdom taking a turn, until all kingdoms are out of points.
 */
  std::vector<int> points, kingdom_index;
  for (int i = 0; i < kingdoms.size(); i++) {
    points.push_back( KINGDOM_EXPANSION_POINTS ); // Defined in kingdom.h
    kingdom_index.push_back( i );
  }

  int iteration = 0, max_points = points.size() * KINGDOM_EXPANSION_POINTS;
  while (!kingdom_index.empty()) {
    iteration++;
    int total_points = 0;
    for (int i = 0; i < points.size(); i++) {
      total_points += points[i];
    }
    int percent = (100 * (max_points - total_points)) / max_points;
    popup_nowait("Placing duchies... [%d%%%%%%%%]", percent);
    for (int i = 0; i < kingdom_index.size(); i++) {
      Kingdom* kingdom = kingdoms[ kingdom_index[i] ];
      if (!kingdom->place_duchy_seat(world, points[i])) {
        kingdom_index.erase( kingdom_index.begin() + i );
        points.erase( points.begin() + i );
      }
    }
  }

// Now each kingdom gets to place minor cities in its duchies.
  for (int i = 0; i < kingdoms.size(); i++) {
    int percent = (100 * (i + 1)) / kingdoms.size();
    popup_nowait("Placing minor cities... [%d%%%%%%%%] [%d/%d]",
                 percent, i + 1, kingdoms.size());
    kingdoms[i]->place_minor_cities(world);
  }

// Build roads from the capital to each duchy.  Building roads from the duchy to
// its minor cities is handled in place_minor_cities().
  for (int i = 0; i < kingdoms.size(); i++) {
    int percent = (100 * (i + 1)) / kingdoms.size();
    popup_nowait("Connecting duchies via road... [%d%%%%%%%%]", percent);
    for (int n = 0; n < kingdoms[i]->dukes.size(); n++) {
      City* capital = kingdoms[i]->capital;
      City* duke = kingdoms[i]->dukes[n];
      kingdoms[i]->build_road( world, capital, duke );
    }
  }

// Finally, swell the territory claimed by each kingdom.
  int expansions = 3;
  for (int n = 0; n < expansions; n++) {
    for (int i = 0; i < kingdoms.size(); i++) {
      popup_nowait("Expanding territories... (%d/%d; %d/%d)",
                   n + 1, expansions, i + 1, kingdoms.size());
      kingdoms[i]->expand_boundaries(world);
    }
  }

// And setup trade routes for all cities!
  for (int i = 0; i < kingdoms.size(); i++) {
    int base_percent = (100 * i) / kingdoms.size();
    kingdoms[i]->setup_trade_routes(base_percent);
  }
}