Code Search for Developers
 
 
  

townclient.cpp from FreePop at Krugle


Show townclient.cpp syntax highlighted

/***************************************************************************
                           townclient.cpp
                           -------------------
    begin                : Wed Jul 14 2004
    copyright            : (C) 2004 by Brendon Higgins
    email                : freepop-devel@lists.sourceforge.net
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include <town.h>
#include <townclient.h>
#include <maptilepos.h>
#include <worldclient.h>
#include <worldpos.h>
#include <client.h>
#include <clientmisc.h>
#include <oversprite.h>
#include <playerclient.h>
#include <peepmagnetclient.h>


TownClient::TownClient(WorldClient* w, const Identity& ident, CL_NetPacket &p,
                       int reason):
    EntityClient(ident),
    sprite(0) {
    onFullUpdate(w, p);
}

TownClient::~TownClient() {
    delete sprite;
}

WorldPos TownClient::getPos() const {
    return pos + MapTilePos(0.5f, 0.5f);
}

void TownClient::onFullUpdate(WorldClient* w, CL_NetPacket& p) {
    pos = MapPos::extract(p.input);
    ownerSlot = p.input.read_int32();
    strength = p.input.read_float32();
    state = p.input.read_int32();
    hasLeader = p.input.read_bool8();
    setSpriteState(w);
}

void TownClient::onMessage(WorldClient* w, int m, CL_NetPacket& p) {
    if (m == Town::Message::STRENGTH) onStrength(p);
    if (m == Town::Message::STATE) onState(w, p);
}

void TownClient::draw(const WorldClient* w) const {
    CL_Point gp = w->getMap()->findPos(getPos());
    sprite->draw(gp.x, gp.y);
    if (hasLeader) {
        // TODO: Offset not builtin
        // HACK, A little bit of a
        PeepMagnetClient::spriteMiniCache->set_color(
                intToCL_Color(w->findPlayer(ownerSlot)->getColour()));
        PeepMagnetClient::spriteMiniCache->draw(gp.x +15, gp.y -30);
    }
}

void TownClient::playerColourChange(WorldClient* w) {
    sprite->set_color(intToCL_Color(w->findPlayer(ownerSlot)->getColour()));
}

void TownClient::displayRotationChange(WorldClient* w, const Rotation& r) {
    setSpriteState(w);
}

void TownClient::onStrength(CL_NetPacket& p) {
    strength = p.input.read_float32();
}

void TownClient::onState(WorldClient* w, CL_NetPacket& p) {
    state = p.input.read_int32();
    strength = p.input.read_float32();
    hasLeader = p.input.read_bool8();
    setSpriteState(w);
}

void TownClient::setSpriteState(const WorldClient* w) {
    delete sprite;
    std::string sn = "entities/towns/human/1/";
    if (state == Town::State::BURNING) {
        sn += "burning";
    } else if (state == Town::State::DEAD) {
        sn += "dead";
    } else {
        sn += "normal";
    }
    sn += "/dir";
    sn += char(w->getDisplayRotation().getClock()) + '0';
    sprite = new OverSprite(sn, app.getResources(), intToCL_Color(
            w->findPlayer(ownerSlot)->getColour()));
}




See more files for this project here

FreePop

FreePop is a multi-platform tile-based game based on the great old game Populous 2 by Bullfrog Productions Ltd., but much improved.

Project homepage: http://sourceforge.net/projects/freepop
Programming language(s): C++
License: other

  Makefile.am
  client.cpp
  client.h
  clientmisc.cpp
  clientmisc.h
  clientstate.cpp
  clientstate.h
  connectstate.cpp
  connectstate.h
  cropsclient.cpp
  cropsclient.h
  entityclient.cpp
  entityclient.h
  entityclientfactory.cpp
  entityclientfactory.h
  firecolumnclient.cpp
  firecolumnclient.h
  gamestate.cpp
  gamestate.h
  loadstate.cpp
  loadstate.h
  mapclient.cpp
  mapclient.h
  maptileclient.cpp
  maptileclient.h
  messagebox.cpp
  messagebox.h
  oversprite.cpp
  oversprite.h
  paintable.cpp
  paintable.h
  pausefader.cpp
  pausefader.h
  peepclient.cpp
  peepclient.h
  peepmagnetclient.cpp
  peepmagnetclient.h
  playerclient.cpp
  playerclient.h
  playeroptionsdialog.cpp
  playeroptionsdialog.h
  rockclient.cpp
  rockclient.h
  swampclient.cpp
  swampclient.h
  townclient.cpp
  townclient.h
  treeclient.cpp
  treeclient.h
  worldclient.cpp
  worldclient.h