3 * Iter Vehemens ad Necem (IVAN)
4 * Copyright (C) Timo Kiviluoto
5 * Released under the GNU General
8 * See LICENSING which should be included
9 * along with this file for more details
13 /* Compiled through charset.cpp */
16 team::team() : Leader(0), ID(0), KillEvilness(0) {
17 //fprintf(stderr, "team:team()!!!\n");
21 team::team(feuLong aID
) : Leader(0), ID(aID
), KillEvilness(0) {
22 //fprintf(stderr, "team:team(%u)\n", ID);
26 void team::Save (outputfile
&SaveFile
) const {
27 SaveFile
<< ID
<< Relation
<< KillEvilness
<< Name
;
31 void team::Load (inputfile
&SaveFile
) {
32 SaveFile
>> ID
>> Relation
>> KillEvilness
>> Name
;
36 std::list
<character
*>::iterator
team::Add (character
*Char
) {
37 return Member
.insert(Member
.end(), Char
);
41 void team::SetRelation (team
*AnotherTeam
, int Relation
) {
42 this->Relation
[AnotherTeam
->ID
] = AnotherTeam
->Relation
[ID
] = Relation
;
46 int team::GetRelation (const team
*AnotherTeam
) const {
47 if (AnotherTeam
!= this) {
48 std::map
<feuLong
, int>::const_iterator Iterator
= Relation
.find(AnotherTeam
->ID
);
49 if (Iterator
!= Relation
.end()) return Iterator
->second
;
50 ABORT("Team %u dismissed! (%u) %p %p", AnotherTeam
->ID
, ID
, AnotherTeam
, this);
56 void team::Hostility (team
*Enemy
) {
57 /* We're testing if the game works better this way... */
58 if (ID
!= PLAYER_TEAM
) return;
59 if (this != Enemy
&& GetRelation(Enemy
) != HOSTILE
) {
60 if (ID
== PLAYER_TEAM
&& game::IsSumoWrestling()) game::EndSumoWrestling(DISQUALIFIED
);
61 /* This is a gum solution. The behaviour should come from the script. */
62 /*if (ID == COLONIST_TEAM && Enemy->ID == NEW_ATTNAM_TEAM) return;*/
63 game::Hostility(this, Enemy
);
64 if (ID
== PLAYER_TEAM
) {
65 if (Enemy
->ID
== ATTNAM_TEAM
) {
66 /* This is a gum solution. The message should come from the script. */
67 if (PLAYER
->CanHear()) ADD_MESSAGE("You hear an alarm ringing.");
68 if (game::GetStoryState() != 2) {
69 v2 AngelPos
= game::GetPetrus() ? game::GetPetrus()->GetPos() : v2(28, 20);
73 for (int c
= 0; c
< 3; ++c
) {
74 if (!c
) Angel
= archangel::Spawn(VALPURUS
); else Angel
= angel::Spawn(VALPURUS
);
76 v2 Where
= game::GetCurrentLevel()->GetNearestFreeSquare(Angel
, AngelPos
);
78 if (Where
== ERROR_V2
) Where
= game::GetCurrentLevel()->GetRandomSquare(Angel
);
79 Angel
->SetTeam(Enemy
);
81 if (Angel
->CanBeSeenByPlayer()) ++Seen
;
83 if (Seen
== 1) ADD_MESSAGE("%s materializes.", Angel
->CHAR_NAME(INDEFINITE
));
84 else if (Seen
== 2) ADD_MESSAGE("Two %s materialize.", Angel
->CHAR_NAME(PLURAL
));
85 else if (Seen
== 3) ADD_MESSAGE("Three %s materialize.", Angel
->CHAR_NAME(PLURAL
));
86 ADD_MESSAGE("\"We will defend the Holy Order!\"");
89 ADD_MESSAGE("You have a feeling this wasn't a good idea...");
91 SetRelation(Enemy
, HOSTILE
);
96 truth
team::HasEnemy () const {
97 for (int c
= 0; c
< game::GetTeams(); ++c
) {
98 if (!game::GetTeam(c
)->GetMember().empty() && GetRelation(game::GetTeam(c
)) == HOSTILE
) return true;
104 int team::GetEnabledMembers () const {
107 for (std::list
<character
*>::const_iterator i
= Member
.begin(); i
!= Member
.end(); ++i
) if ((*i
)->IsEnabled()) ++Amount
;
112 void team::MoveMembersTo (charactervector
&CVector
) {
113 for (std::list
<character
*>::iterator i
= Member
.begin(); i
!= Member
.end(); ++i
) {
114 if ((*i
)->IsEnabled()) {
115 if ((*i
)->GetAction() && (*i
)->GetAction()->IsVoluntary()) (*i
)->GetAction()->Terminate(false);
116 if (!(*i
)->GetAction()) { CVector
.push_back(*i
); (*i
)->Remove(); }
122 void team::Remove (std::list
<character
*>::iterator Iterator
) {
123 if (*Iterator
== Leader
) Leader
= 0;
124 Member
.erase(Iterator
);
128 outputfile
&operator << (outputfile
&SaveFile
, const team
*Team
) {
129 Team
->Save(SaveFile
);
134 inputfile
&operator >> (inputfile
&SaveFile
, team
*&Team
) {
136 Team
->Load(SaveFile
);