~evan-nelson/armagetronad/armagetronad+pcm

« back to all changes in this revision

Viewing changes to src/tron/gAICharacter.cpp

Attempting to create a timeout for PLAYER_CENTER_MESSAGE.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 
3
 
*************************************************************************
4
 
 
5
 
ArmageTron -- Just another Tron Lightcycle Game in 3D.
6
 
Copyright (C) 2000  Manuel Moos (manuel@moosnet.de)
7
 
 
8
 
**************************************************************************
9
 
 
10
 
This program is free software; you can redistribute it and/or
11
 
modify it under the terms of the GNU General Public License
12
 
as published by the Free Software Foundation; either version 2
13
 
of the License, or (at your option) any later version.
14
 
 
15
 
This program is distributed in the hope that it will be useful,
16
 
but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 
GNU General Public License for more details.
19
 
 
20
 
You should have received a copy of the GNU General Public License
21
 
along with this program; if not, write to the Free Software
22
 
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23
 
  
24
 
***************************************************************************
25
 
 
26
 
*/
27
 
 
28
 
#include "gAICharacter.h"
29
 
#include "tDirectories.h"
30
 
#include "tRecorder.h"
31
 
#include <fstream>
32
 
#include <sstream>
33
 
 
34
 
tArray<gAICharacter> gAICharacter::s_Characters(0);
35
 
 
36
 
static REAL weight[AI_PROPERTIES]=
37
 
    {
38
 
        10,
39
 
        10,
40
 
        10,
41
 
        10,
42
 
        10,
43
 
        10,
44
 
        10,
45
 
        10,
46
 
        10,
47
 
        10,
48
 
        0,
49
 
        0,
50
 
        0
51
 
    };
52
 
 
53
 
// load this description from a stream. Return value: success or not?
54
 
bool gAICharacter::Load(std::istream& file)
55
 
{
56
 
    file >> name;
57
 
 
58
 
    iq  = 1;
59
 
    REAL iqt = 1;
60
 
 
61
 
    for (int i=0; i< AI_PROPERTIES; i++)
62
 
    {
63
 
        if (file.eof())
64
 
            return false;
65
 
 
66
 
        file >> properties[i];
67
 
        iq  += properties[i] * weight[i];
68
 
        iqt += weight[i];
69
 
    }
70
 
    iq *= 10/iqt;
71
 
 
72
 
    description.ReadLine(file);
73
 
    return true;
74
 
}
75
 
 
76
 
// loads and adds a single AI from a string to the array
77
 
static bool LoadSingleAI( tString const & line )
78
 
{
79
 
    // build stream from
80
 
    std::stringstream str(static_cast< char const * >( line ) );
81
 
 
82
 
    // gets new character and lets it load the stream
83
 
    int i = gAICharacter::s_Characters.Len();
84
 
    gAICharacter& c = gAICharacter::s_Characters[i];
85
 
    bool ret = c.Load(str);
86
 
 
87
 
    // remove character on failure
88
 
    if ( !ret )
89
 
        gAICharacter::s_Characters.SetLen(i);
90
 
 
91
 
    return ret;
92
 
}
93
 
 
94
 
void gAICharacter::LoadAll(const tString& filename)
95
 
{
96
 
    std::ifstream f;
97
 
 
98
 
    tTextFileRecorder stream( tDirectories::Config(), filename );
99
 
    while( !stream.EndOfFile() )
100
 
    {
101
 
        tString line( stream.GetLine().c_str() );
102
 
        if ( line[0] != '#' )
103
 
            LoadSingleAI( line );
104
 
    }
105
 
}
106