1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
|
/***************************************************************************
graphicset.cpp - description
-------------------
begin : Sun Jan 28 2001
copyright : (C) 2001 by Martin Bickel
email : bickel@asc-hq.org
***************************************************************************/
/*! \file graphicset.cpp
\brief A system that provides a set of images for vehicles, buildings, etc.
*/
/***************************************************************************
* *
* 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 <map>
#include "basestrm.h"
#include "misc.h"
#include "graphicset.h"
// #include "basegfx.h"
#include "errors.h"
#include "typen.h"
#include "sgstream.h"
#include "itemrepository.h"
#include "iconrepository.h"
GraphicSetManager_Base::GraphicSetManager_Base() : activeSet(NULL)
{
}
bool GraphicSetManager_Base :: picAvail ( int num ) const
{
if ( activeSet )
return activeSet->picAvail(num);
else
return false;
}
int GraphicSetManager_Base :: getMode ( int num ) const
{
if ( activeSet && activeSet->picmode.size() > num )
return activeSet->picmode[num];
else
return 0;
}
Surface& GraphicSetManager_Base :: getPic ( int num )
{
if( num >= activeSet->image.size() )
return IconRepository::getIcon("emptyfld.raw");
else
return activeSet->image[num];
}
void GraphicSetManager_Base :: setPic( int num, Surface pic )
{
activeSet->image[num] = pic;
}
int GraphicSetManager_Base :: setActive ( int id )
{
if ( activeSet && id == activeSet->id )
return id;
for ( GraphicSets::iterator i = graphicSets.begin(); i != graphicSets.end(); ++i )
if ( (*i)->id == id ) {
activeSet = *i;
return id;
}
if ( graphicSets.size() < 1 )
fatalError( "no graphic sets (*.gfx) found! Check that asc.gfx is in your search path" );
activeSet = *graphicSets.begin();
return 0;
}
const OverviewMapImage* GraphicSetManager_Base::getQuickView( int id )
{
if ( picAvail ( id )) {
map<int,OverviewMapImage>::iterator qv = activeSet->quickViewImages.find ( id );
if ( qv == activeSet->quickViewImages.end()) {
OverviewMapImage* fqv = new OverviewMapImage ( getPic( id ) );
activeSet->quickViewImages[id] = *fqv;
delete fqv;
return &activeSet->quickViewImages[id];
} else
return &qv->second;
} else {
static OverviewMapImage* emptyFieldQuickView = NULL;
if ( !emptyFieldQuickView )
emptyFieldQuickView = new OverviewMapImage();
return emptyFieldQuickView;
}
}
int getGraphicSetIdFromFilename ( const ASCString& filename )
{
tnfilestream stream ( filename, tnstream::reading );
int magic = stream.readInt();
if ( magic == -1 ) {
return stream.readInt();
} else
return 0;
}
void GraphicSetManager_Base::loadData()
{
if ( activeSet )
return;
#ifdef logging
logtofile("loadbi3graphics");
#endif
loadpalette();
/*
#ifdef genimg
void* mask;
{
int i ;
tnfilestream s ( "largehex.raw", tnstream::reading );
s.readrlepict ( &mask, false, & i );
}
#endif
*/
IconRepository::getIcon("emptyfld.raw");
ASCString location;
tfindfile ff ( "*.gfx" );
ASCString filename = ff.getnextname( NULL, NULL, &location);
while ( !filename.empty() ) {
tnfilestream s ( filename, tnstream::reading );
displayLogMessage ( 5, "loading graphic set " + location + filename + "\n" );
int magic = s.readInt();
if ( magic == -1 ) {
GraphicSet* gs = new GraphicSet;
gs->id = s.readInt();
int picnum = s.readInt();
s.readInt(); // maxPicSize
int* picmode = new int[picnum];
for ( int i = 0; i < picnum; ++i )
picmode[i] = s.readInt();
gs->image.resize ( picnum );
gs->picmode.resize ( picnum );
for ( int i = 0; i < picnum; i++ ) {
if ( picmode[i] >= 1 ) {
Surface& surf = gs->image[i];
surf.read ( s );
if ( surf.w() != fieldsizex || surf.h() != fieldsizey )
surf.strech ( fieldsizex, fieldsizey );
gs->picmode[i] = picmode[i];
} else {
gs->picmode[i] = 256 + 2;
gs->image[i] = IconRepository::getIcon("emptyfld.raw");
}
gs->image[i].assignDefaultPalette();
dataLoaderTicker();
}
delete[] picmode;
graphicSets.push_back ( gs );
}
filename = ff.getnextname();
}
setActive ( 0 );
}
GraphicSetManager_Base::~GraphicSetManager_Base()
{
for ( GraphicSets::iterator i = graphicSets.begin(); i != graphicSets.end(); ++i)
delete *i;
}
|