View Javadoc

1   /*
2    * Created on 25 mars 2005
3    * 
4    *   Magic-Project is a turn based strategy simulator
5    *   Copyright (C) 2003-2007 Fabrice Daugan
6    *
7    *   This program is free software; you can redistribute it and/or modify it 
8    * under the terms of the GNU General Public License as published by the Free 
9    * Software Foundation; either version 2 of the License, or (at your option) any
10   * later version.
11   *
12   *   This program is distributed in the hope that it will be useful, but WITHOUT
13   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14   * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more 
15   * details.
16   *
17   *   You should have received a copy of the GNU General Public License along  
18   * with this program; if not, write to the Free Software Foundation, Inc., 
19   * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20   */
21  package net.sf.magicproject.clickable.targetable.card;
22  
23  import java.util.HashSet;
24  import java.util.Set;
25  
26  import net.sf.magicproject.clickable.targetable.player.Player;
27  
28  /***
29   * @author <a href="mailto:fabdouglas@users.sourceforge.net">Fabrice Daugan </a>
30   * @since 0.83
31   */
32  public final class LastKnownCardInfoImpl implements LastKnownCardInfo {
33  
34  	@SuppressWarnings("unchecked")
35  	LastKnownCardInfoImpl(MCard originalCard, int timestampReferences,
36  			int destinationZone) {
37  		assert timestampReferences > 0;
38  		this.originalCard = originalCard;
39  		this.destinationZone = destinationZone;
40  		this.idColor = originalCard.getIdColor();
41  		this.idCard = originalCard.getIdCard();
42  		this.tapped = originalCard.tapped;
43  		this.cachedRegisters = originalCard.cachedRegisters.clone();
44  		this.cachedProperties = (Set<Integer>) ((HashSet<Integer>) originalCard.cachedProperties)
45  				.clone();
46  
47  		this.controller = originalCard.controller;
48  		this.owner = originalCard.owner;
49  		this.timestamp = originalCard.getTimestamp();
50  		this.timestampReferences = timestampReferences;
51  	}
52  
53  	/***
54  	 * Create and return a LastKnownCard object build with the last known
55  	 * informations.
56  	 * 
57  	 * @return a LastKnownCard object build with the last known informations.
58  	 */
59  	public LastKnownCard createLastKnownCard() {
60  		return new LastKnownCard(originalCard, destinationZone, idColor, idCard,
61  				tapped, cachedRegisters, controller, owner, cachedProperties,
62  				timestamp, timestampReferences);
63  	}
64  
65  	/***
66  	 * Remove a reference to the given timestamp of card.
67  	 * 
68  	 * @param timestamp
69  	 *          the timestamp reference
70  	 * @return true if the given timestamp is no more referenced.
71  	 */
72  	public boolean removeTimestamp(int timestamp) {
73  		return --timestampReferences <= 0;
74  	}
75  
76  	/***
77  	 * The last known colors.
78  	 */
79  	private int idColor;
80  
81  	/***
82  	 * The last known card identifiant.
83  	 */
84  	private int idCard;
85  
86  	/***
87  	 * The last known registers.
88  	 */
89  	private int[] cachedRegisters;
90  
91  	/***
92  	 * The last known controller.
93  	 */
94  	private Player controller;
95  
96  	/***
97  	 * The last known owner.
98  	 */
99  	private Player owner;
100 
101 	/***
102 	 * The last known properties.
103 	 */
104 	private Set<Integer> cachedProperties;
105 
106 	/***
107 	 * The last known information on tap state.
108 	 */
109 	private boolean tapped;
110 
111 	/***
112 	 * The original card.
113 	 */
114 	private MCard originalCard;
115 
116 	/***
117 	 * The timestamp of card when it has been saved.
118 	 */
119 	private int timestamp;
120 
121 	/***
122 	 * The amount of references to the original card with the specific timestamp.
123 	 */
124 	private int timestampReferences;
125 
126 	/***
127 	 * The destination zone of this card before it moved.
128 	 */
129 	private int destinationZone;
130 }