Google
Web alhem.net
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

MapForm.cpp

Go to the documentation of this file.
00001 /*
00002 Copyright (C) 2003  Anders Hedstrom
00003 
00004 This program is free software; you can redistribute it and/or
00005 modify it under the terms of the GNU General Public License
00006 as published by the Free Software Foundation; either version 2
00007 of the License, or (at your option) any later version.
00008 
00009 This program is distributed in the hope that it will be useful,
00010 but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 GNU General Public License for more details.
00013 
00014 You should have received a copy of the GNU General Public License
00015 along with this program; if not, write to the Free Software
00016 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017 */
00018 
00019 #include <stdio.h>
00020 #include <stdlib.h>
00021 #include <mysql/mysql.h>
00022 #include <libsql++.h>
00023 #include <string>
00024 using std::string;
00025 #include <libcgi++.h>
00026 #include <libwolfshade.h>
00027 #include <libgd.h>
00028 
00029 #include "BaseForm.h"
00030 #include "WolfshadeWeb.h"
00031 #include "Map.h"
00032 #include "MapForm.h"
00033 
00034 
00035 namespace cgi
00036 {
00037 
00038 
00039 MapForm::MapForm(Web *web)
00040 :BaseForm(web, "mapform")
00041 ,m_vzone(0)
00042 {
00043         Query q(GetDatabase());
00044 
00045         q.get_result("select * from room where virtual_room<>0");
00046         while (q.fetch_row())
00047         {
00048                 db::Room *tmp = new db::Room(GetDatabase(),&q);
00049                 m_vroom[tmp -> num] = tmp;
00050         }
00051         q.free_result();
00052 
00053 }
00054 
00055 
00056 MapForm::~MapForm()
00057 {
00058         for (rooms_t::iterator it = m_vroom.begin(); it != m_vroom.end(); it++)
00059         {
00060                 delete (*it).second;
00061         }
00062 }
00063 
00064 
00065 void MapForm::Process()
00066 {
00067         WolfshadeWeb *web = static_cast<WolfshadeWeb *>(GetWeb());
00068         char action[200];
00069         
00070         if (GetForm() -> getvalue("mapform",action,200))
00071         {
00072                 char slask[100];
00073                 if (!strcmp(action,"vzone"))
00074                 {
00075                         GetForm() -> getvalue("vzone",slask,100);
00076                         m_vzone = atol(slask);
00077                 }
00078                 if (!strcmp(action,"map"))
00079                 {
00080                         char sql[200];
00081                         // 'map' is vzone num - got ya
00082                         GetForm() -> getvalue("map",slask,100);
00083                         long map = atol(slask);
00084                         int level = 0;
00085                         sprintf(sql,"select * from vmap where vzone=%ld and level=%d",map,level);
00086                         db::Vmap x(GetDatabase(),sql);
00087                         if (!x.pic)
00088                         {
00089                                 CreatePicture("/tmp/map_pic.gif",map,level);
00090                                 x.pic = AddPic(x.pic,"/tmp/map_pic.gif");
00091                                 x.save();
00092                         }
00093                         db::Pic pic(GetDatabase(),x.pic);
00094                         web -> SetPic(pic.pic,pic.ext);
00095                 }
00096         }
00097 }
00098 
00099 
00100 void MapForm::Select(const string &)
00101 {
00102 }
00103 
00104 
00105 void MapForm::List()
00106 {
00107 }
00108 
00109 
00110 void MapForm::Display(long)
00111 {
00112         WolfshadeWeb *web = static_cast<WolfshadeWeb *>(GetWeb());
00113         Database *db = GetDatabase();
00114         Query q(db);
00115 
00116         if (m_vzone)
00117         {
00118                 printf("<img src=%s?%s=map&map=%ld&lvl=0>",
00119                         GetCgiName().c_str(),
00120                         GetFormName().c_str(),m_vzone);
00121         }
00122 }
00123 
00124 
00125 void MapForm::CreatePicture(const string &filename,long vzonenum,int level)
00126 {
00127         db::Vzone vz(GetDatabase(),vzonenum);
00128         Map map(GetDatabase(),vzonenum,level);
00129         gd::Image img(vz.sizex,vz.sizey,vz.sizex,vz.sizey);
00130         int black = img.AddColor(0,0,0);
00131         int colors[256];
00132 
00133         for (int i = 0; i < 256; i++)
00134                 colors[i] = 0;
00135         colors[0] = black;
00136         for (int i = 'a'; i < 'z'; i++)
00137         {
00138                 int tmp = i - 'a';
00139                 int intensity = 4 * tmp / 8;
00140                 int r = (tmp & 1) ? 0x33 : 0;
00141                 int g = (tmp & 2) ? 0x33 : 0;
00142                 int b = (tmp & 4) ? 0x33 : 0;
00143                 r *= intensity;
00144                 g *= intensity;
00145                 b *= intensity;
00146                 colors[i] = img.AddColor(r,g,b);
00147         }
00148         for (int y = 0; y < vz.sizey; y++)
00149         {
00150                 for (int x = 0; x < vz.sizex; x++)
00151                 {
00152                         char c = map.GetAt(x,y);
00153                         if (!colors[c])
00154                                 colors[c] = img.AddColor(random()%256,random()%256,random()%256);
00155                         img.Line(x,y,x,y,colors[c]);
00156                 }
00157         }
00158         {
00159                 FILE *fil = fopen(filename.c_str(),"wb");
00160                 if (fil)
00161                 {
00162                         img.SaveTo(fil);
00163                         fclose(fil);
00164                 }
00165         }
00166 }
00167 
00168 
00169 } // namespace cgi
00170 
00171 

Generated for Wolfshade by doxygen 1.3.6

Page, code, and content Copyright (C) 2004 by Anders Hedström