1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
  
     | 
    
      /**
	Team account
	Allied players share a common account.
	
	@author Maikel
*/
protected func Initialize()
{
	// Under no circumstance there may by multiple copies of this rule.
	if (ObjectCount(Find_ID(Rule_TeamAccount)) > 1)
		return RemoveObject();
	return;
}
// Only SetWealth needs to be overloaded, DoWealth just uses that.
global func SetWealth(int plr, int wealth)
{
	// Only if team account rule is activated.
	if (!FindObject(Find_ID(Rule_TeamAccount)))
		return _inherited(plr, wealth, ...);
		
	// Only for valid players.
	if (plr == NO_OWNER || !GetPlayerName(plr))
		return _inherited(plr, wealth, ...);
		
	// Also set wealth of all allies.
	for (var i = 0; i < GetPlayerCount(); i++)
	{
		var to_plr = GetPlayerByIndex(i);
		if (to_plr != plr && !Hostile(to_plr, plr))
			_inherited(to_plr, wealth, ...);
	}
	return _inherited(plr, wealth, ...);
}
protected func InitializePlayer(int plr)
{
	// Find an ally and add this wealth.
	for (var i = 0; i < GetPlayerCount(); i++)
	{
		var to_plr = GetPlayerByIndex(i);
		if (to_plr != plr && !Hostile(to_plr, plr))
		{
			DoWealth(to_plr, GetWealth(plr));
			break;
		}
	}	
	return;
}
protected func RemovePlayer(int plr)
{
	// Nothing should happen here.
	return;
}
protected func OnTeamSwitch(int player, int new_team, int old_team)
{
	// Remove player from old team, i.e. substract his fair share.
	var count = 0;
	for (var i = 0; i < GetPlayerCount(); i++)
	{
		if (!Hostile(player, GetPlayerByIndex(i)))
			count++;		
	}
	//var share = GetWealth(player) / count;
	// Add player to new team, i.e. add his wealth.
	// TODO Implement
	return;
}
protected func OnHostilityChange(int plr, int plr2, bool hostility, bool old_hostility)
{
	// TODO: Implement
	return;
}
public func Activate(int by_plr)
{
	MessageWindow(this.Description, by_plr);
	return true;
}
/*-- Proplist --*/
local Name = "$Name$";
local Description = "$Description$";
local Visibility = VIS_Editor;
local EditorPlacementLimit = 1; // Rules are to be placed only once
 
     |