'g'o should not miss items in corners anymore
[k8-i-v-a-n.git] / src / game / team.cpp
blobf3c6fb2c03bdeb5118b024ebdeb60cafce617681
1 /*
3 * Iter Vehemens ad Necem (IVAN)
4 * Copyright (C) Timo Kiviluoto
5 * Released under the GNU General
6 * Public License
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) {
37 if (!Who) return;
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 (!this) return UNCARING;
50 if (AnotherTeam != this) {
51 std::map<feuLong, int>::const_iterator Iterator = Relation.find(AnotherTeam->ID);
52 if (Iterator != Relation.end()) return Iterator->second;
53 ABORT("Team %u dismissed! (%u) %p %p", AnotherTeam->ID, ID, AnotherTeam, this);
55 return FRIEND;
59 void team::Hostility (team *Enemy) {
60 /* We're testing if the game works better this way... */
61 if (ID != PLAYER_TEAM) return; //HACK!
62 if (this != Enemy && GetRelation(Enemy) != HOSTILE) {
63 if (ID == PLAYER_TEAM && game::IsSumoWrestling()) game::EndSumoWrestling(DISQUALIFIED);
64 /* This is a gum solution. The behaviour should come from the script. */
65 /*if (ID == COLONIST_TEAM && Enemy->ID == NEW_ATTNAM_TEAM) return;*/
66 game::Hostility(this, Enemy);
67 if (ID == PLAYER_TEAM) {
68 if (Enemy->ID == ATTNAM_TEAM) {
69 /* This is a gum solution. The message should come from the script. */
70 if (PLAYER->CanHear()) ADD_MESSAGE("You hear an alarm ringing.");
71 if (game::GetStoryState() != 2) {
72 v2 AngelPos = game::GetPetrus() ? game::GetPetrus()->GetPos() : v2(28, 20);
73 int Seen = 0;
74 angel *Angel;
75 for (int c = 0; c < 3; ++c) {
76 if (!c) Angel = archangel::Spawn(VALPURUS); else Angel = angel::Spawn(VALPURUS);
77 v2 Where = game::GetCurrentLevel()->GetNearestFreeSquare(Angel, AngelPos);
78 if (Where == ERROR_V2) {
79 Where = game::GetCurrentLevel()->GetRandomSquare(Angel);
80 if (Where == ERROR_V2) {
81 delete Angel;
82 return;
85 Angel->SetTeam(Enemy);
86 Angel->PutTo(Where);
87 if (Angel->CanBeSeenByPlayer()) ++Seen;
89 if (Seen == 1) ADD_MESSAGE("%s materializes.", Angel->CHAR_NAME(INDEFINITE));
90 else if (Seen == 2) ADD_MESSAGE("Two %s materialize.", Angel->CHAR_NAME(PLURAL));
91 else if (Seen == 3) ADD_MESSAGE("Three %s materialize.", Angel->CHAR_NAME(PLURAL));
92 ADD_MESSAGE("\"We will defend the Holy Order!\"");
95 ADD_MESSAGE("You have a feeling this wasn't a good idea...");
97 SetRelation(Enemy, HOSTILE);
102 truth team::HasEnemy () const {
103 for (int c = 0; c < game::GetTeams(); ++c) {
104 if (!game::GetTeam(c)->GetMember().empty() && GetRelation(game::GetTeam(c)) == HOSTILE) return true;
106 return false;
110 int team::GetEnabledMembers () const {
111 int Amount = 0;
113 for (std::list<character*>::const_iterator i = Member.begin(); i != Member.end(); ++i) if ((*i)->IsEnabled()) ++Amount;
114 return Amount;
118 void team::MoveMembersTo (charactervector &CVector) {
119 for (std::list<character *>::iterator i = Member.begin(); i != Member.end(); ++i) {
120 if ((*i)->IsEnabled()) {
121 if ((*i)->GetAction() && (*i)->GetAction()->IsVoluntary()) (*i)->GetAction()->Terminate(false);
122 if (!(*i)->GetAction()) { CVector.push_back(*i); (*i)->Remove(); }
128 void team::Remove (character *Who) {
129 if (!Who) return;
130 if (Who == Leader) Leader = 0;
131 for (auto it = Member.begin(); it != Member.end(); ++it) {
132 if (*it == Who) { Member.erase(it); return; }
137 outputfile &operator << (outputfile &SaveFile, const team *Team) {
138 Team->Save(SaveFile);
139 return SaveFile;
143 inputfile &operator >> (inputfile &SaveFile, team *&Team) {
144 Team = new team;
145 Team->Load(SaveFile);
146 return SaveFile;