summaryrefslogtreecommitdiffstats
path: root/game/code/meta/triggerlocator.cpp
blob: 30f8fe3073413d91b8ce0fc5937d0e75f8e6a1a1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
//=============================================================================
// Copyright (C) 2002 Radical Entertainment Ltd.  All rights reserved.
//
// File:        
//
// Description: Implement TriggerLocator
//
// History:     04/04/2002 + Created -- Cary Brisebois
//
//=============================================================================

//========================================
// System Includes
//========================================
// Foundation Tech
#include <raddebug.hpp>

//========================================
// Project Includes
//========================================
#ifndef WORLD_BUILDER
#include <meta/TriggerLocator.h>
#include <meta/TriggerVolume.h>
#include <meta/triggervolumetracker.h>
#include <memory/srrmemory.h>
#else
#include "TriggerLocator.h"
#include "TriggerVolume.h"
#include "triggervolumetracker.h"
#define new(s) new
#endif

//******************************************************************************
//
// Global Data, Local Data, Local Classes
//
//******************************************************************************

//******************************************************************************
//
// Public Member Functions
//
//******************************************************************************

//==============================================================================
// TriggerLocator::TriggerLocator
//==============================================================================
// Description: Constructor.
//
// Parameters:	None.
//
// Return:      N/A.
//
//==============================================================================
TriggerLocator::TriggerLocator() :
    mTriggerVolumes( NULL ),
    mNumTriggers( 0 ),
    mMaxNumTriggers( 0 ),
    mPlayerEntered( false ),
    mPlayerID( -1 )
{
}

//==============================================================================
// TriggerLocator::~TriggerLocator
//==============================================================================
// Description: Destructor.
//
// Parameters:	None.
//
// Return:      N/A.
//
//==============================================================================
TriggerLocator::~TriggerLocator()
{
    unsigned int i;

    for ( i = 0; i < mMaxNumTriggers; ++i )
    {
        if ( mTriggerVolumes[ i ] != NULL )
        {
            //Chuck We should check if the Trig Track even exists
            // since it maybe destroyed when we are clearing the inventory of these things.
            if(GetTriggerVolumeTracker() != NULL)
            {
                GetTriggerVolumeTracker( )->RemoveTrigger( mTriggerVolumes[ i ] );
            }
            mTriggerVolumes[ i ]->Release( );
            mTriggerVolumes[ i ] = NULL;
        }
    }

    delete[] mTriggerVolumes;
    mTriggerVolumes = NULL;
}

//=============================================================================
// TriggerLocator::SetNumTriggers
//=============================================================================
// Description: Comment
//
// Parameters:  ( unsigned int num, int allocID )
//
// Return:      void 
//
//=============================================================================
void TriggerLocator::SetNumTriggers( unsigned int num, int allocID )
{
    MEMTRACK_PUSH_GROUP( "TriggerLocator" );
    rAssert( !mTriggerVolumes );

    #ifdef RAD_DEBUG
        if ( allocID == 0 )
        {
            rDebugString( "Someone is allocating trigger volume space in the DEFAULT heap!\n");
            rDebugString( "Pass the correct allocator id to SetNumTriggers please!!\n");
        }
    #endif


    mTriggerVolumes = new( (GameMemoryAllocator)allocID ) TriggerVolume*[num];
    mMaxNumTriggers = (short)num;
 
    unsigned short i;
    for ( i = 0; i < mMaxNumTriggers; ++i )
    {
        mTriggerVolumes[ i ] = NULL;
    }
    MEMTRACK_POP_GROUP( "TriggerLocator" );
}

//=============================================================================
// TriggerLocator::AddTriggerVolume
//=============================================================================
// Description: Comment
//
// Parameters:  ( TriggerVolume* volume )
//
// Return:      void 
//
//=============================================================================
void TriggerLocator::AddTriggerVolume( TriggerVolume* volume )
{
    rAssert( mNumTriggers < mMaxNumTriggers );
    rAssert( mTriggerVolumes );

    if ( volume )
    {
        volume->AddRef();

        mTriggerVolumes[ mNumTriggers ] = volume;
        mNumTriggers++;
    }
}

//=============================================================================
// TriggerLocator::GetTriggerVolume
//=============================================================================
// Description: Comment
//
// Parameters:  ( unsigned int i )
//
// Return:      TriggerVolume
//
//=============================================================================
TriggerVolume* TriggerLocator::GetTriggerVolume( unsigned int i )
{
    rAssert( i < mMaxNumTriggers );
    rAssert( mTriggerVolumes );

    return mTriggerVolumes[ i ];
}

//=============================================================================
// TriggerLocator::IsPlayerTracked
//=============================================================================
// Description: Comment
//
// Parameters:  ( int playerID )
//
// Return:      unsigned int 
//
//=============================================================================
unsigned int TriggerLocator::IsPlayerTracked( int playerID ) const
{
    unsigned int count = 0;
    unsigned int i;
    for ( i = 0; i < mNumTriggers; ++i )
    {
        if ( mTriggerVolumes[ i ] && mTriggerVolumes[ i ]->IsPlayerTracking( playerID ) )
        {
            ++count;
        }
    }

    return count;
}

//******************************************************************************
//
// Private Member Functions
//
//******************************************************************************