void PoolGroup<T>::SpawnObject(ActivePoolData& spawns, uint32 limit,
		uint32 triggerFrom) {
	uint32 lastDespawned = 0;
	int count = limit - spawns.GetActiveObjectCount(poolId);

	// If triggered from some object respawn this object is still marked as spawned
	// and also counted into m_SpawnedPoolAmount so we need increase count to be
	// spawned by 1
	if (triggerFrom)
		++count;

	// This will try to spawn the rest of pool, not guaranteed
	for (int i = 0; i < count; ++i) {
		PoolObject* obj = RollOne(spawns, triggerFrom);
		if (!obj)
			continue;
		if (obj->guid == lastDespawned)
			continue;

		if (obj->guid == triggerFrom) {
			ReSpawn1Object(obj);
			triggerFrom = 0;
			continue;
		}
		spawns.ActivateObject<T>(obj->guid, poolId);
		Spawn1Object(obj);

		if (triggerFrom) {
			// One spawn one despawn no count increase
			DespawnObject(spawns, triggerFrom);
			lastDespawned = triggerFrom;
			triggerFrom = 0;
		}
	}
}
示例#2
0
int main (int argc, const char * argv[]) {
	int		rolls[ kMaxRoll + 1 ], threeDice, i;
	
	srand( clock() );
	
	for ( i=0; i<=kMaxRoll; i++ )
		rolls[ i ] = 0;
	
	for ( i=1; i <= 1000; i++ ) {
		threeDice = RollOne() + RollOne() + RollOne();
		++ rolls[ threeDice ];
	}
	
	PrintRolls( rolls );
	
	return 0;
}
示例#3
0
文件: main.c 项目: JackIrish/ios
int main (int argc, const char * argv[])
{
	int rolls[ 13 ], twoDice, i;
	
	srand( clock() );
	
	for ( i = 0; i < 13; i++ )
		rolls[ i ] = 0;
	
	for ( i = 1; i <= 1000; i++ ) {
		twoDice = RollOne() + RollOne();
		++ rolls[ twoDice ];
	}
	
	PrintRolls( rolls );
	
	return 0;
}
示例#4
0
void PoolGroup<T>::SpawnObject(MapPersistentState& mapState, uint32 limit, uint32 triggerFrom, bool instantly)
{
    SpawnedPoolData& spawns = mapState.GetSpawnedPoolData();

    uint32 lastDespawned = 0;
    int count = limit - spawns.GetSpawnedObjects(poolId);

    // If triggered from some object respawn this object is still marked as spawned
    // and also counted into m_SpawnedPoolAmount so we need increase count to be
    // spawned by 1
    if (triggerFrom)
    {
        if (spawns.IsSpawnedObject<T>(triggerFrom))
            ++count;
        else
            triggerFrom = 0;
    }

    // This will try to spawn the rest of pool, not guaranteed
    for (int i = 0; i < count; ++i)
    {
        PoolObject* obj = RollOne(spawns, triggerFrom);
        if (!obj)
            continue;
        if (obj->guid == lastDespawned)
            continue;

        if (obj->guid == triggerFrom)
        {
            MANGOS_ASSERT(spawns.IsSpawnedObject<T>(obj->guid));
            MANGOS_ASSERT(spawns.GetSpawnedObjects(poolId) > 0);
            ReSpawn1Object(mapState, obj);
            triggerFrom = 0;
            continue;
        }

        spawns.AddSpawn<T>(obj->guid, poolId);
        Spawn1Object(mapState, obj, instantly);

        if (triggerFrom)
        {
            // One spawn one despawn no count increase
            DespawnObject(mapState, triggerFrom);
            lastDespawned = triggerFrom;
            triggerFrom = 0;
        }
    }
}
示例#5
0
void PoolGroup<T>::SpawnObject(uint32 limit, bool cache)
{
    if (limit == 1)                                         // This is the only case where explicit chance is used
    {
        uint32 roll = RollOne();
        if (cache && m_LastDespawnedNode != roll)
            Despawn1Object(m_LastDespawnedNode);

        m_LastDespawnedNode = 0;
        Spawn1Object(roll);
    }
    else if (limit < EqualChanced.size() && m_SpawnedPoolAmount < limit)
    {
        std::vector<uint32> IndexList;
        for (size_t i = 0; i < EqualChanced.size(); ++i)
            if (!EqualChanced[i].spawned)
                IndexList.push_back(i);

        while (m_SpawnedPoolAmount < limit && IndexList.size() > 0)
        {
            uint32 roll = urand(1, IndexList.size()) - 1;
            uint32 index = IndexList[roll];
            if (!cache || (cache && EqualChanced[index].guid != m_LastDespawnedNode))
            {
                if (cache)
                    Despawn1Object(m_LastDespawnedNode);

                EqualChanced[index].spawned = Spawn1Object(EqualChanced[index].guid);
            }
            else
                EqualChanced[index].spawned = ReSpawn1Object(EqualChanced[index].guid);

            if (EqualChanced[index].spawned)
                ++m_SpawnedPoolAmount;                      // limited group use the Spawned variable to store the number of actualy spawned creatures

            std::vector<uint32>::iterator itr = IndexList.begin()+roll;
            IndexList.erase(itr);
        }
        m_LastDespawnedNode = 0;
    }
    else  // Not enough objects in pool, so spawn all
    {
        for (size_t i = 0; i < EqualChanced.size(); ++i)
            EqualChanced[i].spawned = Spawn1Object(EqualChanced[i].guid);
    }
}
示例#6
0
void PoolGroup<T>::SpawnObject(uint32 limit, uint32 triggerFrom)
{
    uint32 lastDespawned = 0;
    int count = limit - m_SpawnedPoolAmount;

    // If triggered from some object respawn this object is still marked as spawned
    // and also counted into m_SpawnedPoolAmount so we need increase count to be 
    // spawned by 1
    if (triggerFrom)
        ++count;

    // This will try to spawn the rest of pool, not guaranteed
    for (int i = 0; i < count; ++i)
    {
        int index;
        PoolObjectList* store;

        RollOne(index, &store, triggerFrom);
        if (index == -1)
            continue;
        if ((*store)[index].guid == lastDespawned)
            continue;

        if ((*store)[index].guid == triggerFrom)
        {
            (*store)[index].spawned = ReSpawn1Object(triggerFrom);
            triggerFrom = 0;
            continue;
        }
        else
            (*store)[index].spawned = Spawn1Object((*store)[index].guid);

        if (triggerFrom)
        {
            // One spawn one despawn no count increase
            DespawnObject(triggerFrom);
            lastDespawned = triggerFrom;
            triggerFrom = 0;
        }
        else
            ++m_SpawnedPoolAmount;
    }
}