src/character/clothe.cpp

Go to the documentation of this file.
00001 /******************************************************************************
00002  *  Wormux is a convivial mass murder game.
00003  *  Copyright (C) 2001-2004 Lawrence Azzoug.
00004  *
00005  *  This program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; either version 2 of the License, or
00008  *  (at your option) any later version.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
00018  ******************************************************************************
00019  *****************************************************************************/
00020 
00021 #include "clothe.h"
00022 #include <map>
00023 #include <iostream>
00024 #include "member.h"
00025 #include "../tool/xml_document.h"
00026 #include "../tool/string_tools.h"
00027 
00028 Clothe::Clothe(xmlpp::Element *xml, std::map<std::string, Member*>& members_lst)
00029 {
00030   XmlReader::ReadStringAttr( xml, "name", name);
00031 
00032   xmlpp::Node::NodeList nodes = xml -> get_children("member");
00033   xmlpp::Node::NodeList::iterator
00034     it=nodes.begin(),
00035     end=nodes.end();
00036 
00037   for (; it != end; ++it)
00038   {
00039     xmlpp::Element *elem = dynamic_cast<xmlpp::Element*> (*it);
00040     assert (elem != NULL);
00041     std::string att;
00042     if (!XmlReader::ReadStringAttr(elem, "name", att))
00043     {
00044       std::cerr << "Malformed attached member definition" << std::endl;
00045       continue;
00046     }
00047 
00048     Member* member = NULL;
00049     if(members_lst.find(att) != members_lst.end())
00050     {
00051       member = members_lst.find(att)->second;
00052     }
00053     else
00054     {
00055       std::cerr << "Undefined member \"" << att << "\"" << std::endl;
00056     }
00057 
00058     int lay=0;
00059     if(XmlReader::ReadIntAttr(elem, "layer", lay))
00060     {
00061       if((uint)lay >= layers.size())
00062         layers.resize( lay+1, (Member*)NULL);
00063       layers[lay] = member;
00064     }
00065   }
00066 
00067   std::vector<Member*>::iterator i = layers.begin();
00068   while( i != layers.end())
00069   if(*i!=NULL)
00070     i++;
00071   else
00072     i=layers.erase(i);
00073 }
00074 
00075 Clothe::Clothe(Clothe* c, std::map<std::string, Member*>& members_lst)
00076 {
00077   name = c->name;
00078 
00079   for (std::vector<Member*>::iterator it = c->layers.begin();
00080       it != c->layers.end();
00081       ++it)
00082   {
00083     layers.push_back(members_lst.find((*it)->name)->second);
00084   }
00085 }
00086 
00087 Clothe::~Clothe()
00088 {
00089   layers.clear();
00090 }

Generated on Mon Jan 1 13:10:55 2007 for Wormux by  doxygen 1.4.7