Code Search for Developers
 
 
  

cropsclient.cpp from FreePop at Krugle


Show cropsclient.cpp syntax highlighted

/***************************************************************************
                           cropsclient.cpp
                           -------------------
    begin                : Fri Dec 10 2004
    copyright            : (C) 2004 by Brendon Lloyd Higgins
    email                : bh_doc@users.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 <client.h>
#include <clientmisc.h>
#include <maptilepos.h>
#include <crops.h>
#include <cropsclient.h>
#include <playerclient.h>
#include <rules.h>
#include <worldclient.h>
#include <worldpos.h>
#include <oversprite.h>
#include <rules.h>

OverSprite* CropsClient::spriteCache = 0;
OverSprite* CropsClient::spriteBurningCache = 0;
OverSprite* CropsClient::spriteDeadCache = 0;

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

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

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

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

void CropsClient::onMessage(WorldClient* w, int m, CL_NetPacket& p) {
    if (m == Crops::Message::STATE) onState(w, p);
}

int CropsClient::drawSortIndex(const WorldClient* w) const {
    return w->getMap()->findPos(getPos()).y - MapTileClient::picHeightOn2();
}

bool CropsClient::drawUpdate(const WorldClient *w, unsigned int d) {
    sprite->update(d / 1000.0f);
    return true;
}

void CropsClient::draw(const WorldClient* w) const {
    CL_Point gp = w->getMap()->findPos(getPos());
    sprite->draw(gp.x, gp.y);
}

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

void CropsClient::onState(WorldClient* w, CL_NetPacket& p) {
    state = p.input.read_int32();
    setSpriteState(w);
}

void CropsClient::setSpriteState(WorldClient* w) {
    delete sprite;
    if (state == Crops::State::BURNING) {
        sprite = new OverSprite(*spriteBurningCache,
                                 intToCL_Color(w->findPlayer(ownerSlot)->getColour()));
    } else if (state == Crops::State::DEAD) {
        sprite = new OverSprite(*spriteDeadCache,
                                 intToCL_Color(w->findPlayer(ownerSlot)->getColour()));
    } else {
        // It doesn't matter if we draw the decayed state as normal since this should be the state
        // it used to be in, and the entity will be removed pretty soon, anyhow.
        sprite = new OverSprite(*spriteCache,
                                 intToCL_Color(w->findPlayer(ownerSlot)->getColour()));
    }
}

void CropsClient::loadSprites(Rules* r) {
    spriteCache = new OverSprite("entities/crops/human/" + r->theater
            + "/normal", app.getResources());
    spriteBurningCache = new OverSprite("entities/crops/human/" + r->theater
            + "/burning", app.getResources());
    spriteDeadCache = new OverSprite("entities/crops/human/" + r->theater
            + "/dead", app.getResources());
}

void CropsClient::freeSprites() {
    delete spriteCache;
    delete spriteBurningCache;
    delete spriteDeadCache;
}




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