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 void team::Add (character
*Who
) {
38 for (auto &it
: Member
) if (it
== Who
) return;
39 Member
.insert(Member
.end(), Who
);
43 void team::SetRelation (team
*AnotherTeam
, int Relation
) {
44 this->Relation
[AnotherTeam
->ID
] = AnotherTeam
->Relation
[ID
] = Relation
;
48 int team::GetRelation (const team
*AnotherTeam
) const {
49 if (AnotherTeam
!= this) {
50 std::map
<feuLong
, int>::const_iterator Iterator
= Relation
.find(AnotherTeam
->ID
);
51 if (Iterator
!= Relation
.end()) return Iterator
->second
;
52 ABORT("Team %u dismissed! (%u) %p %p", AnotherTeam
->ID
, ID
, AnotherTeam
, this);
58 void team::Hostility (team
*Enemy
) {
59 /* We're testing if the game works better this way... */
60 if (ID
!= PLAYER_TEAM
) return;
61 if (this != Enemy
&& GetRelation(Enemy
) != HOSTILE
) {
62 if (ID
== PLAYER_TEAM
&& game::IsSumoWrestling()) game::EndSumoWrestling(DISQUALIFIED
);
63 /* This is a gum solution. The behaviour should come from the script. */
64 /*if (ID == COLONIST_TEAM && Enemy->ID == NEW_ATTNAM_TEAM) return;*/
65 game::Hostility(this, Enemy
);
66 if (ID
== PLAYER_TEAM
) {
67 if (Enemy
->ID
== ATTNAM_TEAM
) {
68 /* This is a gum solution. The message should come from the script. */
69 if (PLAYER
->CanHear()) ADD_MESSAGE("You hear an alarm ringing.");
70 if (game::GetStoryState() != 2) {
71 v2 AngelPos
= game::GetPetrus() ? game::GetPetrus()->GetPos() : v2(28, 20);
75 for (int c
= 0; c
< 3; ++c
) {
76 if (!c
) Angel
= archangel::Spawn(VALPURUS
); else Angel
= angel::Spawn(VALPURUS
);
78 v2 Where
= game::GetCurrentLevel()->GetNearestFreeSquare(Angel
, AngelPos
);
80 if (Where
== ERROR_V2
) Where
= game::GetCurrentLevel()->GetRandomSquare(Angel
);
81 Angel
->SetTeam(Enemy
);
83 if (Angel
->CanBeSeenByPlayer()) ++Seen
;
85 if (Seen
== 1) ADD_MESSAGE("%s materializes.", Angel
->CHAR_NAME(INDEFINITE
));
86 else if (Seen
== 2) ADD_MESSAGE("Two %s materialize.", Angel
->CHAR_NAME(PLURAL
));
87 else if (Seen
== 3) ADD_MESSAGE("Three %s materialize.", Angel
->CHAR_NAME(PLURAL
));
88 ADD_MESSAGE("\"We will defend the Holy Order!\"");
91 ADD_MESSAGE("You have a feeling this wasn't a good idea...");
93 SetRelation(Enemy
, HOSTILE
);
98 truth
team::HasEnemy () const {
99 for (int c
= 0; c
< game::GetTeams(); ++c
) {
100 if (!game::GetTeam(c
)->GetMember().empty() && GetRelation(game::GetTeam(c
)) == HOSTILE
) return true;
106 int team::GetEnabledMembers () const {
109 for (std::list
<character
*>::const_iterator i
= Member
.begin(); i
!= Member
.end(); ++i
) if ((*i
)->IsEnabled()) ++Amount
;
114 void team::MoveMembersTo (charactervector
&CVector
) {
115 for (std::list
<character
*>::iterator i
= Member
.begin(); i
!= Member
.end(); ++i
) {
116 if ((*i
)->IsEnabled()) {
117 if ((*i
)->GetAction() && (*i
)->GetAction()->IsVoluntary()) (*i
)->GetAction()->Terminate(false);
118 if (!(*i
)->GetAction()) { CVector
.push_back(*i
); (*i
)->Remove(); }
124 void team::Remove (character
*Who
) {
126 if (Who
== Leader
) Leader
= 0;
127 for (auto it
= Member
.begin(); it
!= Member
.end(); ++it
) {
128 if (*it
== Who
) { Member
.erase(it
); return; }
133 outputfile
&operator << (outputfile
&SaveFile
, const team
*Team
) {
134 Team
->Save(SaveFile
);
139 inputfile
&operator >> (inputfile
&SaveFile
, team
*&Team
) {
141 Team
->Load(SaveFile
);