Debian Codegraph @

engine/action/action_die.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 action_die.cpp - The die action. */
11 //
12 // (c) Copyright 1998-2005 by Lutz Sammer 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 <stdio.h>
36 #include <stdlib.h>
37
38 #include "stratagus.h"
39 #include "unittype.h"
40 #include "animation.h"
41 #include "player.h"
42 #include "unit.h"
43 #include "actions.h"
44 #include "map.h"
45
46 /*----------------------------------------------------------------------------
47 -- Functions
48 ----------------------------------------------------------------------------*/
49
50 /**
51 ** Unit dies!
52 **
53 ** @param unit The unit which dies.
54 */
55 void HandleActionDie(CUnit *unit)
56 {
57 //
58 // Show death animation
59 //
60 if (unit->Type->Animations && unit->Type->Animations->Death) {
61 UnitShowAnimation(unit, unit->Type->Animations->Death);
62 } else {
63 // some units has no death animation
64 unit->Anim.Unbreakable = 0;
65 }
66
67 //
68 // Die sequence terminated, generate corpse.
69 //
70 if (!unit->Anim.Unbreakable) {
71 if (!unit->Type->CorpseType) {
72 // We may be in the cache if we just finished out death animation
73 // even though there is no corpse.
74 // (unit->Type->Animations && unit->Type->Animations->Death)
75 // Remove us from the map to be safe
76 unit->Remove(NULL);
77 unit->Release();
78 return;
79 }
80
81 Assert(unit->Type->TileWidth == unit->Type->CorpseType->TileWidth &&
82 unit->Type->TileHeight == unit->Type->CorpseType->TileHeight);
83
84 // Update sight for new corpse
85 // We have to unmark BEFORE changing the type.
86 // Always do that, since types can have different vision properties.
87 MapUnmarkUnitSight(unit);
88 unit->Type = unit->Type->CorpseType;
89 unit->CurrentSightRange = unit->Type->Stats[unit->Player->Index].Variables[SIGHTRANGE_INDEX].Max;
90 MapMarkUnitSight(unit);
91
92 // We must be dead to get here, it we aren't we need to know why
93 // This assert replaces and old DEBUG message "Reset to die is really needed"
94 Assert(unit->Orders[0]->Action == UnitActionDie);
95
96 unit->SubAction = 0;
97 unit->Frame = 0;
98 UnitUpdateHeading(unit);
99 if (unit->Type->Animations && unit->Type->Animations->Death) {
100 UnitShowAnimation(unit, unit->Type->Animations->Death);
101 }
102 }
103 }
104
105 //@}