view api/WarFoundryCore.cs @ 104:2f3cafb69799

Re #121: Migrate to AGPL license * Update all API files to AGPL license * Include AGPL license and remove GPL/LGPL documents * Fix copyright dates where they're known
author IBBoard <dev@ibboard.co.uk>
date Sat, 15 Aug 2009 10:36:50 +0000
parents 3ea0ab04352b
children 52cacdbcb001
line source
1 // This file (WarFoundryCore.cs) is a part of the IBBoard.WarFoundry.API project and is copyright 2007, 2008, 2009 IBBoard.
2 //
3 // The file and the library/program it is in are licensed and distributed, without warranty, under the GNU Affero GPL license, either version 3 of the License or (at your option) any later version. Please see COPYING for more information and the full license.
5 using System;
6 using IBBoard.Logging;
7 using IBBoard.WarFoundry.API.Objects;
9 namespace IBBoard.WarFoundry.API
10 {
11 public class WarFoundryCore
12 {
13 public static readonly int INFINITY = -1;
14 public static event GameSystemChangedDelegate GameSystemChanged;
15 public static event ArmyChangedDelegate ArmyChanged;
17 private static GameSystem system;
18 private static Army currentArmy;
20 public static GameSystem CurrentGameSystem
21 {
22 get { return system; }
23 set
24 {
25 if (system==null || !system.Equals(value))
26 {
27 GameSystem oldSystem = system;
28 system = value;
30 if (system==null)
31 {
32 LogNotifier.Debug(typeof(WarFoundryCore), "Game system set to null");
33 }
34 else
35 {
36 LogNotifier.DebugFormat(typeof(WarFoundryCore), "Game system set to {0} with ID {1}", system.Name, system.ID);
37 }
39 if (GameSystemChanged!=null)
40 {
41 GameSystemChanged(oldSystem, system);
42 }
44 //If we've changed the game system then we can't keep the current army
45 CurrentArmy = null;
46 }
47 }
48 }
50 public static Army CurrentArmy
51 {
52 get { return currentArmy; }
53 set
54 {
55 if (currentArmy==null || !currentArmy.Equals(value))
56 {
57 /*if (currentArmy!=null)
58 {
59 currentArmy.UnitAdded-= UnitAddedMethod;
60 currentArmy.UnitRemoved-= UnitRemovedMethod;
61 currentArmy.PointsValueChanged-= PointsValueChangedMethod;
62 currentArmy.FailedRequirement-=FailedUnitRequirementMethod;
63 }*/
64 Army oldArmy = currentArmy;
65 currentArmy = value;
67 if (currentArmy!=null)
68 {
69 CurrentGameSystem = currentArmy.GameSystem; //Set the game system in case the new army is from a different system
70 }
72 /*if (currentArmy!=null)
73 {
74 currentArmy.UnitAdded+= UnitAddedMethod;
75 currentArmy.UnitRemoved+= UnitRemovedMethod;
76 currentArmy.PointsValueChanged+= PointsValueChangedMethod;
77 currentArmy.FailedRequirement+=FailedUnitRequirementMethod;
78 }*/
80 if (ArmyChanged!=null)
81 {
82 ArmyChanged(oldArmy, currentArmy);
83 }
84 }
85 }
86 }
87 }
88 }