Beispiel #1
0
bool PickupItem::OnTrigger(HOBJECT hSender, const CParsedMsg &cMsg)
{
	static CParsedMsg::CToken s_cTok_Activate("ACTIVATE");
	static CParsedMsg::CToken s_cTok_Team( "TEAM" );

	if( cMsg.GetArg(0) == s_cTok_Activate )
	{
		// Can't activate before we've respawned.
		if( m_bWasPickedUp )
			return true;

		// If the object is dead, it can't pick up stuff...

		if (IsPlayer(hSender))
		{
			CPlayerObj* pPlayer = (CPlayerObj*)g_pLTServer->HandleToObject(hSender);

			if (!pPlayer || pPlayer->IsDead()) return true;

			SetPlayerObj(hSender);

			ObjectTouch(hSender);
		}
		else
		{
			SetPlayerObj(LTNULL);
			return true;
		}
	}
	else if (cMsg.GetArg(0) == s_cTok_Team)
	{
		if( cMsg.GetArgCount( ) > 1 )
		{
			uint32 nTeamId = atoi( cMsg.GetArg( 1 ));
			if( nTeamId < MAX_TEAMS )
			{
				SetTeamId( nTeamId );
			}
			else
			{
				SetTeamId( INVALID_TEAM );
			}

			return true;
		}
	}
	else
		return GameBase::OnTrigger(hSender, cMsg);

	return true;
}
bool AIObjectiveMarker::Advance()
{
    if( !AIObjective::s_objectivesInitialised && g_app->m_multiwinia->m_gameType == Multiwinia::GameTypeAssault) return false;

    if( !m_registered && m_objectiveId != -1) 
    {
        AIObjective *b = (AIObjective*)g_app->m_location->GetBuilding( m_objectiveId );
        b->RegisterObjectiveMarker( m_id.GetUniqueId(), (m_armourObjective == 1 && m_pickupOnly != 1) );
        m_registered = true;
        if( b->m_defenseObjective ) m_defenseMarker = true;
        if( m_id.GetTeamId() != 255 )
        {
            m_defaultTeam = m_id.GetTeamId();
            SetTeamId(255);
        }

        // see if there is a building present in the same area as the marker
        // if there is, assume that is the objective and check that instead of the number of darwinians
        for( int i = 0; i < g_app->m_location->m_buildings.Size(); ++i )
        {
            if( g_app->m_location->m_buildings.ValidIndex(i) )
            {
                Building *b = g_app->m_location->m_buildings[i];
                if( b &&
                    (b->m_pos - m_pos).Mag() < 20.0 )
                {
                    if( b->m_type != Building::TypeAIObjectiveMarker &&
                        b->m_type != Building::TypeAITarget &&
                        b->m_type != Building::TypeWall &&
                        b->m_type != Building::TypeLaserFence &&
                        b->m_type != Building::TypeStaticShape )
                    {
                        m_objectiveBuildingId = b->m_id.GetUniqueId();
                        break;
                    }
                }
            }
        }
    }

	// Only run this code sometimes
	m_timer -= SERVER_ADVANCE_PERIOD;
    if( m_timer > 0.0 ) return false;

    m_timer = 2.0;

    if( g_app->m_multiwinia->m_gameType == Multiwinia::GameTypeRocketRiot ) AdvanceRocketRiot();
    else if( m_defenseMarker ) AdvanceDefensive();
    else                  AdvanceStandard();

    

    return false;
}
void AIObjectiveMarker::AdvanceDefensive()
{
    AIObjective *objective = (AIObjective *)g_app->m_location->GetBuilding( m_objectiveId );
    if( objective && objective->m_active )
    {
        Building *b = g_app->m_location->GetBuilding( m_objectiveBuildingId );
        if( b )
        {
            if( b->m_type == Building::TypeSolarPanel &&
                b->GetNumPorts() == 0 )
            {
                m_objectiveBuildingId = -1;
            }
        }
        else
        {
            m_objectiveBuildingId = -1;
        }

        int teamCounts[NUM_TEAMS];
        memset( teamCounts, 0, sizeof(int) * NUM_TEAMS );
        for( int i = 0; i < NUM_TEAMS; ++i )
        {
            if( i == g_app->m_location->GetMonsterTeamId() ) continue;
            if( i == g_app->m_location->GetFuturewinianTeamId() ) continue;
            teamCounts[i] = g_app->m_location->m_entityGrid->GetNumFriends( m_pos.x, m_pos.z, m_scanRange, i );
        }

        int currentWinner = 0;
        int totalDefenders = 0;
        for( int i = 0; i < NUM_TEAMS; ++i )
        {
            if( g_app->m_location->IsDefending(i) ) 
            {
                totalDefenders += teamCounts[i];
                if( totalDefenders >= 15 ||
                    (b && g_app->m_location->IsDefending( b->m_id.GetTeamId() ) ) )
                {
                    currentWinner = i;
                    break;
                }
            }

            if( teamCounts[i] > (teamCounts[currentWinner] * 2 )  )
                currentWinner = i;
        }

        SetTeamId( currentWinner );
    }


    int id = AI::FindNearestTarget( m_pos );
    AITarget *target = (AITarget *)g_app->m_location->GetBuilding( id );
    if( target )
    {
        for( int i = 0; i < NUM_TEAMS; ++i )
        {
            if( g_app->m_location->IsDefending(i) )
            {
                AI *ai = AI::s_ai[i];
                if( ai )
                {
                    if( ai->m_currentObjective == m_objectiveId )
                    {
                        if(g_app->m_location->IsFriend(m_id.GetTeamId(), i )) 
                        {
                            target->m_priority[i] = 1.0;
                            target->m_aiObjectiveTarget[i] = true;
                        }
                        else
                        {
                            target->m_aiObjectiveTarget[i] = false;
                        }
                    }
                    else
                    {
                        target->m_aiObjectiveTarget[i] = false;
                    }
                }
            }
        }
    }
}
void AIObjectiveMarker::AdvanceStandard()
{
    AIObjective *objective = (AIObjective *)g_app->m_location->GetBuilding( m_objectiveId );
    if( objective && objective->m_active )
    {
        if( m_objectiveBuildingId != -1 )
        {
            Building *b = g_app->m_location->GetBuilding( m_objectiveBuildingId );
            if( b && !b->m_destroyed )
            {
                if( b->m_type == Building::TypeSolarPanel &&
                    b->GetNumPorts() == 0 )
                {
                    m_objectiveBuildingId = -1;
                }
                else
                {
                    SetTeamId( b->m_id.GetTeamId() );
                }
            }
            else
            {
                AppDebugOut("Registered Objective Building missing\n");
                m_objectiveBuildingId = -1;
            }
        }

        if( m_objectiveBuildingId == -1 )
        {
            if( m_scanRange == 0.0 )
            {
                SetTeamId(m_defaultTeam);
            }
            else
            {
                bool include[NUM_TEAMS];
                memset( include, true, sizeof(bool) * NUM_TEAMS );
                include[g_app->m_location->GetMonsterTeamId()] = false;
                include[g_app->m_location->GetFuturewinianTeamId()] = false;
                int total = g_app->m_location->m_entityGrid->GetNumNeighbours( m_pos.x, m_pos.z, m_scanRange, include );
                if( total > 0 )
                {
                    int teamCounts[NUM_TEAMS];
                    memset( teamCounts, 0, sizeof(int) * NUM_TEAMS );
                    for( int i = 0; i < NUM_TEAMS; ++i )
                    {
                        if( i == g_app->m_location->GetMonsterTeamId() ) continue;
                        if( i == g_app->m_location->GetFuturewinianTeamId() ) continue;
                        teamCounts[i] = g_app->m_location->m_entityGrid->GetNumFriends( m_pos.x, m_pos.z, m_scanRange, i );
                    }

                    int currentWinner = 0;
                    for( int i = 0; i < NUM_TEAMS; ++i )
                    {
                        if( teamCounts[i] > (teamCounts[currentWinner] * 4 ) &&
                            teamCounts[currentWinner] < 10) currentWinner = i;
                    }

                    SetTeamId( currentWinner );
                }
                else
                {
                    SetTeamId(255);
                }
            }
        }
    }

    int id = AI::FindNearestTarget( m_pos );
    AITarget *target = (AITarget *)g_app->m_location->GetBuilding( id );
    if( target )
    {
        for( int i = 0; i < NUM_TEAMS; ++i )
        {
            if( g_app->m_location->IsAttacking(i) )
            {
                AI *ai = AI::s_ai[i];
                if( ai )
                {
                    if( ai->m_currentObjective == m_objectiveId )
                    {
                        if( m_armourObjective == 0 )
                        {
                            if(!g_app->m_location->IsFriend(m_id.GetTeamId(), i )) 
                            {
                                target->m_priority[i] = 1.0;
                                target->m_aiObjectiveTarget[i] = true;
                            }
                            else
                            {
                                target->m_aiObjectiveTarget[i] = false;
                            }
                        }
                        else
                        {
                            target->m_aiObjectiveTarget[i] = false;
                        }
                    }
                    else if( m_pickupAvailable )
                    {
                        target->m_priority[i] = 1.0;
                        target->m_aiObjectiveTarget[i] = true;
                    }
                    else
                    {
                        target->m_aiObjectiveTarget[i] = false;
                    }
                }
            }
        }
    }
}