Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List

Salvage.cpp

00001 /*
00002 Copyright 2003 - 2005 Elliott Kleinrock, Dan Neely, Kurt W. Over, Damon Domjan
00003 
00004 This file is part of FreeStars, a free clone of the Stars! game.
00005 
00006 FreeStars is free software; you can redistribute it and/or modify
00007 it under the terms of the GNU General Public License as published by
00008 the Free Software Foundation; either version 2 of the License, or
00009 (at your option) any later version.
00010 
00011 FreeStars is distributed in the hope that it will be useful,
00012 but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 GNU General Public License for more details.
00015 
00016 You should have received a copy of the GNU General Public License
00017 along with FreeStars; if not, write to the Free Software
00018 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 
00020 The full GPL Copyright notice should be in the file COPYING.txt
00021 
00022 Contact:
00023 Email Elliott at 9jm0tjj02@sneakemail.com
00024 */
00025 
00026 #include "FSServer.h"
00027 
00028 #ifdef _DEBUG
00029 #define new DEBUG_NEW
00030 #endif
00031 
00032 
00033 Salvage::Salvage()
00034 :       mOwner(NULL),
00035         TurnCreated(TheGame->GetTurn()),
00036         MaxSize(0)
00037 {
00038         SetID(0);
00039 }
00040 
00041 Salvage::Salvage(const CargoHolder &source)
00042 :       CargoHolder(source),
00043         TurnCreated(TheGame->GetTurn()),
00044         MaxSize(0)
00045 {
00046         SetID(TheGalaxy->GetSalvageID());
00047 }
00048 
00049 Salvage::~Salvage()
00050 {
00051 }
00052 
00053 void Salvage::Decay()
00054 {
00055         if (TheGame->GetTurn() > TurnCreated + 1) {
00056                 for (CargoType ct = 0; ct < Rules::MaxMinType; ++ct) {
00057                         long amt = GetContain(ct);
00058                         if (amt > 100)
00059                                 amt /= 10;
00060                         else
00061                                 amt = min(amt, 10L);
00062 
00063                         AdjustAmounts(ct, -amt);
00064                         MaxSize -= amt;
00065                 }
00066         }
00067 }
00068 
00069 bool Salvage::ParseNode(const TiXmlNode * node)
00070 {
00071         if (!CargoHolder::ParseNode(node))
00072                 return false;
00073 
00074         TurnCreated = GetLong(node->FirstChild("TurnCreated"));
00075         if (TurnCreated < 1 || TurnCreated >= TheGame->GetTurn()) {
00076                 Message * mess = TheGame->AddMessage("Error: Wrong year number in turn file");
00077                 mess->AddLong("Salvage created", TurnCreated);
00078                 return false;
00079         }
00080 
00081         return true;
00082 }
00083 
00084 TiXmlNode * Salvage::WriteNode(TiXmlNode * node, const Player * viewer) const
00085 {
00086         if (viewer != NULL && !SeenBy(viewer))
00087                 return NULL;
00088 
00089         CargoHolder::WriteNode(node, viewer);
00090         if (viewer == NULL)
00091                 AddLong(node, "TurnCreated", TurnCreated);
00092 
00093         return node;
00094 }

Generated on Mon Aug 8 21:33:45 2005 for Freestars by  doxygen 1.4.2-20050421