1 /*
2 *
3 * Iter Vehemens ad Necem (IVAN)
4 * Copyright (C) Timo Kiviluoto
5 * Released under the GNU General
6 * Public License
7 *
8 * See LICENSING which should be included
9 * along with this file for more details
10 *
11 */
12
13 /* Compiled through charset.cpp */
14
team()15 team::team() : Leader(0) { }
team(ulong ID)16 team::team(ulong ID) : Leader(0), ID(ID), KillEvilness(0) { }
Add(character * Char)17 std::list<character*>::iterator team::Add(character* Char) { return Member.insert(Member.end(), Char); }
18
SetRelation(team * AnotherTeam,int Relation)19 void team::SetRelation(team* AnotherTeam, int Relation)
20 {
21 this->Relation[AnotherTeam->ID] = AnotherTeam->Relation[ID] = Relation;
22 }
23
GetRelation(const team * AnotherTeam) const24 int team::GetRelation(const team* AnotherTeam) const
25 {
26 if(AnotherTeam != this)
27 {
28 std::map<ulong, int>::const_iterator Iterator = Relation.find(AnotherTeam->ID);
29
30 if(Iterator != Relation.end())
31 return Iterator->second;
32 else
33 ABORT("Team %lu dismissed!", AnotherTeam->ID);
34 }
35
36 return FRIEND;
37 }
38
Hostility(team * Enemy)39 void team::Hostility(team* Enemy)
40 {
41 /* We're testing if the game works better this way... */
42
43 if(ID != PLAYER_TEAM)
44 return;
45
46 if(this != Enemy && GetRelation(Enemy) != HOSTILE)
47 {
48 if(ID == PLAYER_TEAM && game::IsSumoWrestling())
49 game::EndSumoWrestling(DISQUALIFIED);
50
51 /* This is a gum solution. The behaviour should come from the script. */
52
53 /*if(ID == COLONIST_TEAM && Enemy->ID == NEW_ATTNAM_TEAM)
54 return;*/
55
56 game::Hostility(this, Enemy);
57
58 if(ID == PLAYER_TEAM)
59 {
60 if(Enemy->ID == ATTNAM_TEAM)
61 {
62 /* This is a gum solution. The message should come from the script. */
63 if(PLAYER->CanHear())
64 ADD_MESSAGE("You hear an alarm ringing.");
65
66 if(game::GetGloomyCaveStoryState() != 2)
67 {
68 v2 AngelPos = game::GetPetrus() ? game::GetPetrus()->GetPos() : v2(28, 20);
69 int Seen = 0;
70 angel* Angel;
71
72 for(int c = 0; c < 3; ++c)
73 {
74 if(!c)
75 Angel = archangel::Spawn(VALPURUS);
76 else
77 Angel = angel::Spawn(VALPURUS);
78
79 v2 Where = game::GetCurrentLevel()->GetNearestFreeSquare(Angel, AngelPos);
80
81 if(Where == ERROR_V2)
82 Where = game::GetCurrentLevel()->GetRandomSquare(Angel);
83
84 Angel->SetTeam(Enemy);
85 Angel->PutTo(Where);
86
87 if(Angel->CanBeSeenByPlayer())
88 ++Seen;
89 }
90
91 if(Seen == 1)
92 ADD_MESSAGE("%s materializes.", Angel->CHAR_NAME(INDEFINITE));
93 else if(Seen == 2)
94 ADD_MESSAGE("Two %s materialize.", Angel->CHAR_NAME(PLURAL));
95 else if(Seen == 3)
96 ADD_MESSAGE("Three %s materialize.", Angel->CHAR_NAME(PLURAL));
97
98 ADD_MESSAGE("\"We will defend the Holy Order!\"");
99 }
100 }
101
102 ADD_MESSAGE("You have a feeling this wasn't a good idea...");
103 }
104
105 SetRelation(Enemy, HOSTILE);
106 }
107 }
108
Save(outputfile & SaveFile) const109 void team::Save(outputfile& SaveFile) const
110 {
111 SaveFile << ID << Relation << KillEvilness;
112 }
113
Load(inputfile & SaveFile)114 void team::Load(inputfile& SaveFile)
115 {
116 SaveFile >> ID >> Relation >> KillEvilness;
117 }
118
HasEnemy() const119 truth team::HasEnemy() const
120 {
121 for(int c = 0; c < game::GetTeams(); ++c)
122 if(!game::GetTeam(c)->GetMember().empty() && GetRelation(game::GetTeam(c)) == HOSTILE)
123 return true;
124
125 return false;
126 }
127
GetEnabledMembers() const128 int team::GetEnabledMembers() const
129 {
130 int Amount = 0;
131
132 for(character* p : Member)
133 if(p->IsEnabled())
134 ++Amount;
135
136 return Amount;
137 }
138
operator <<(outputfile & SaveFile,const team * Team)139 outputfile& operator<<(outputfile& SaveFile, const team* Team)
140 {
141 Team->Save(SaveFile);
142 return SaveFile;
143 }
144
operator >>(inputfile & SaveFile,team * & Team)145 inputfile& operator>>(inputfile& SaveFile, team*& Team)
146 {
147 Team = new team;
148 Team->Load(SaveFile);
149 return SaveFile;
150 }
151
MoveMembersTo(charactervector & CVector)152 void team::MoveMembersTo(charactervector& CVector)
153 {
154 for(character* p : Member)
155 if(p->IsEnabled())
156 {
157 if(p->GetAction() && p->GetAction()->IsVoluntary())
158 p->GetAction()->Terminate(false);
159
160 if(!p->GetAction())
161 {
162 CVector.push_back(p);
163 p->Remove();
164 }
165 }
166 }
167
Remove(std::list<character * >::iterator Iterator)168 void team::Remove(std::list<character*>::iterator Iterator)
169 {
170 if(*Iterator == Leader)
171 Leader = 0;
172
173 Member.erase(Iterator);
174 }
175