Esempio n. 1
0
static int l_fac_add_to_factions(lua_State *L)
{
	FactionBuilder *facbld = l_fac_check_builder(L, 1);
	Faction *fac = facbld->fac;

	const std::string factionName(luaL_checkstring(L, 2));

	if (!facbld->registered && !facbld->skip) {
		if (facbld->fac->hasHomeworld) {
			printf("l_fac_add_to_factions: added (%3d,%3d,%3d) f=%4.0f e=%2.2f '%s' [%s]\n"
				, fac->homeworld.sectorX, fac->homeworld.sectorY, fac->homeworld.sectorZ, fac->foundingDate, fac->expansionRate, fac->name.c_str(), factionName.c_str());
		}
		else {
			printf("l_fac_add_to_factions: added '%s' [%s]\n", fac->name.c_str(), factionName.c_str());
		}

		// add the faction to the various faction data structures
		s_factions.push_back(facbld->fac);
		s_factions_byName[facbld->fac->name] = facbld->fac;
		s_spatial_index.Add(facbld->fac);

		if (facbld->fac->hasHomeworld) s_homesystems.insert(facbld->fac->homeworld.SystemOnly());
		facbld->fac->idx = s_factions.size()-1;
		facbld->registered = true;

		return 0;
	} else if (facbld->skip) {
		printf("l_fac_add_to_factions: invalid homeworld, skipped (%3d,%3d,%3d) f=%4.0f e=%2.2f '%s' [%s]\n"
				, fac->homeworld.sectorX, fac->homeworld.sectorY, fac->homeworld.sectorZ, fac->foundingDate, fac->expansionRate, fac->name.c_str(), factionName.c_str());
		return 0;
	} else {
		return luaL_error(L, "faction '%s' already added\n", facbld->fac->name.c_str());
	}
}
Esempio n. 2
0
void Faction::Uninit()
{
	for (FactionIterator it = s_factions.begin(); it != s_factions.end(); ++it) {
		delete *it;
	}
	s_factions.clear();
	s_factions_byName.clear();
}
Esempio n. 3
0
Faction* Faction::GetNearestFaction(const Sector sec, Uint32 sysIndex)
{
	/* firstly if this a custom StarSystem it may already have a faction assigned
	*/
	if (sec.m_systems[sysIndex].customSys && sec.m_systems[sysIndex].customSys->faction) {
		return sec.m_systems[sysIndex].customSys->faction;
	}

	/* if it didn't, or it wasn't a custom StarStystem, then we go ahead and assign it a faction allegiance like normal below...
	*/
	Faction*    result             = &s_no_faction;
	double      closestFactionDist = HUGE_VAL;
	FactionList candidates         = s_spatial_index.CandidateFactions(sec, sysIndex);

	for (FactionIterator it = candidates.begin(); it != candidates.end(); ++it) {
		if ((*it)->IsCloserAndContains(closestFactionDist, sec, sysIndex)) result = *it;
	}
	return result;
}
Esempio n. 4
0
void CharSheetManager::_processFactionRequest(Message* message,DispatchClient* client)
{
    PlayerObject* player = gWorldManager->getPlayerByAccId(client->getAccountId());

    if(player == NULL)
    {
        DLOG(info) << "CharSheetManager::_processFactionRequest: could not find player " << client->getAccountId();
        return;
    }

    gMessageFactory->StartMessage();
    gMessageFactory->addUint32(opFactionResponseMessage);
    gMessageFactory->addString(player->getFaction());
    gMessageFactory->addUint32(player->getFactionPointsByFactionId(2));
    gMessageFactory->addUint32(player->getFactionPointsByFactionId(3));
    gMessageFactory->addUint32(0);

    FactionList* factions = player->getFactionList();

    gMessageFactory->addUint32(factions->size());

    FactionList::iterator it = factions->begin();

    while(it != factions->end())
    {
        gMessageFactory->addString(mvFactions[(*it).first - 1]);
        ++it;
    }

    gMessageFactory->addUint32(factions->size());

    it = factions->begin();

    while(it != factions->end())
    {
        gMessageFactory->addFloat((float)((*it).second));
        ++it;
    }

    Message* newMessage = gMessageFactory->EndMessage();

    client->SendChannelA(newMessage,client->getAccountId(),CR_Client,6);
}
Esempio n. 5
0
//static
void Faction::Init()
{
	lua_State *L = luaL_newstate();
	LUA_DEBUG_START(L);

	pi_lua_open_standard_base(L);

	LuaConstants::Register(L);

	LUA_DEBUG_CHECK(L, 0);

	RegisterFactionsAPI(L);

	LUA_DEBUG_CHECK(L, 0);
	pi_lua_dofile_recursive(L, "factions");

	LUA_DEBUG_END(L, 0);
	lua_close(L);

	printf("Number of factions added: " SIZET_FMT "\n", s_factions.size());
	StarSystem::ShrinkCache();    // clear the star system cache of anything we used for faction generation
}
Esempio n. 6
0
const Uint32 Faction::GetNumFactions()
{
	return s_factions.size();
}
Esempio n. 7
0
Faction *Faction::GetFaction(const Uint32 index)
{
	assert( index < s_factions.size() );
	return s_factions[index];
}