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