Debian Codegraph @

engine/ai/ai_magic.cpp

raw
1 // ____ _ __
2 // / __ )____ _____ | | / /___ ___________
3 // / __ / __ \/ ___/ | | /| / / __ `/ ___/ ___/
4 // / /_/ / /_/ (__ ) | |/ |/ / /_/ / / (__ )
5 // /_____/\____/____/ |__/|__/\__,_/_/ /____/
6 //
7 // A futuristic real-time strategy game.
8 // This file is part of Bos Wars.
9 //
10 /**@name ai_magic.cpp - AI magic functions. */
11 //
12 // (c) Copyright 2002-2009 by Lutz Sammer, Joris Dauphin, and Jimmy Salmon
13 //
14 // This program is free software; you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation; only version 2 of the License.
17 //
18 // This program is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 // GNU General Public License for more details.
22 //
23 // You should have received a copy of the GNU General Public License
24 // along with this program; if not, write to the Free Software
25 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26 // 02111-1307, USA.
27 //
28
29 //@{
30
31 /*----------------------------------------------------------------------------
32 -- Includes
33 ----------------------------------------------------------------------------*/
34
35 #include "stratagus.h"
36 #include "unittype.h"
37 #include "unit.h"
38 #include "spells.h"
39 #include "ai_local.h"
40 #include "player.h"
41
42 /*----------------------------------------------------------------------------
43 -- Functions
44 ----------------------------------------------------------------------------*/
45
46 /**
47 ** Auto cast a spell
48 **
49 ** @param unit The unit to cast a spell
50 */
51 static void AiAutoCastSpell(CUnit *unit)
52 {
53 if (!unit->Type->CanCastSpell)
54 {
55 return;
56 }
57
58 for (size_t i = 0; i < SpellTypeTable.size(); ++i)
59 {
60 // Check if we can cast this spell.
61 if (unit->Type->CanCastSpell[i] &&
62 (SpellTypeTable[i]->AutoCast || SpellTypeTable[i]->AICast))
63 {
64 if (AutoCastSpell(unit, SpellTypeTable[i]))
65 {
66 // Spell was cast
67 return;
68 }
69 }
70 }
71 }
72
73 /**
74 ** Check what computer units can do with magic.
75 ** In fact, turn on autocast for AI.
76 */
77 void AiCheckMagic()
78 {
79 for (int i = 0; i < AiPlayer->Player->TotalNumUnits; ++i)
80 {
81 AiAutoCastSpell(AiPlayer->Player->Units[i]);
82 }
83 }
84
85 //@}