Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames

Betrayal.BetrayalTeam


00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
/******************************************************************************
BetrayalTeam

Creation date: 2010-01-31 15:24
Last change: $Id$
Copyright (c) 2010, Wormbo
******************************************************************************/

class BetrayalTeam extends ReplicationInfo;


const MAX_TEAMMATES = 3;
var BetrayalPRI Teammates[MAX_TEAMMATES];

//Value of the shared pot
var int TeamPot;

replication
{
	reliable if (bNetDirty)
		TeamPot, Teammates;
}


function bool AddTeammate(BetrayalPRI NewTeammate, int MaxTeamSize)
{
	local int i, NumTeammates;
	local Bot B;

	if (TeamPot > NewTeammate.RogueValue / 2) {
		// don't add to teams that already have significant pots
		return false;
	}

	//Count current team size
	for (i = 0; i < MAX_TEAMMATES; i++) {
		if (Teammates[i] != None) {
			NumTeammates++;
		}
	}

	MaxTeamSize = Min(MaxTeamSize, MAX_TEAMMATES);
	if (NumTeammates >= MaxTeamSize) {
		return false;
	}

	for (i = 0; i < MAX_TEAMMATES; i++) {
		if (Teammates[i] == NewTeammate) {
			// already added
			return true;
		}

		if (Teammates[i] == None || Teammates[i].bDeleteMe) {
			NewTeammate.CurrentTeam = self;
			Teammates[i] = NewTeammate;
			//NewTeamMate.TeamChanged();

			B = Bot(NewTeamMate.Owner);
			if (B != None && BetrayalSquadAI(B.Squad) != None)
				BetrayalSquadAI(B.Squad).SetNewTeam(Self);

			// save to reuse i here
			for (i = 0; i < MAX_TEAMMATES; i++) {
				// prevent bot from instantly attacking new teammates
				if (Teammates[i] != None) {
					B = Bot(Teammates[i].Owner);
					if (B != None && BetrayalSquadAI(B.Squad) != None)
						BetrayalSquadAI(B.Squad).NotifyNewTeammate(NewTeammate);
				}
			}
			return true;
		}
	}

	return false;
}

function bool MemberWasBetrayedBy(BetrayalPRI PRI)
{
	local int i;

	if (PRI.BetrayedTeam == Self)
		return true; // actually betrayed this team

	for (i = 0; i < MAX_TEAMMATES; i++) {
		if (Teammates[i] != None && PRI.Betrayed == Teammates[i])
			return true; // betrayed a new member of this team
	}
	return false;
}

function int LoseTeammate(BetrayalPRI OldTeammate)
{
	local int i, NumTeammates;
	local Bot B;

	OldTeammate.CurrentTeam = None;
	//OldTeammate.TeamChanged();
	B = Bot(OldTeammate.Owner);
	if (B != None && BetrayalSquadAI(B.Squad) != None)
		BetrayalSquadAI(B.Squad).SetNewTeam(None);

	NetUpdateTime = Level.TimeSeconds - 1;
	for (i = 0; i < MAX_TEAMMATES; i++) {
		if (Teammates[i] == None || Teammates[i] == OldTeammate || Teammates[i].bDeleteMe) {
			Teammates[i] = None;
		}
		else {
			NumTeammates++;
		}
	}

	//Returns number of teammates left after removing a player
	return NumTeammates;
}

/**
Discard temporary teams on reset.
*/
function Reset()
{
	local int i;

	for (i = 0; i < MAX_TEAMMATES; i++) {
		if (Teammates[i] != None)
			LoseTeammate(Teammates[i]);
	}

	if (BetrayalGame(Level.Game) != None)
		BetrayalGame(Level.Game).RemoveTeam(Self);
	Destroy();
}


//=============================================================================
// Default values
//=============================================================================

defaultproperties
{
	NetUpdateFrequency = 2
}

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: So 31.7.2011 11:54:30.000 - Creation time: Do 14.8.2014 09:58:35.069 - Created with UnCodeX