MissileProcess.cpp

Go to the documentation of this file.
00001 /*
00002 Copyright (C) 2003-2007 The Pentagram team
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 
00020 
00021 // This class is DEPRECATED.
00022 // It only exists to provide backward compatibility for savegames
00023 
00024 
00025 
00026 #include "pent_include.h"
00027 
00028 #include "MissileProcess.h"
00029 #include "Item.h"
00030 #include "getObject.h"
00031 
00032 #include "IDataSource.h"
00033 #include "ODataSource.h"
00034 
00035 // p_dynamic_cast stuff
00036 DEFINE_RUNTIME_CLASSTYPE_CODE(MissileProcess,Process);
00037 
00038 MissileProcess::MissileProcess()
00039         : Process()
00040 {
00041 
00042 }
00043 
00044 bool MissileProcess::run(const uint32 /*framenum*/)
00045 {
00046         // some values to make items use a nice arc :-)
00047         // (No, this isn't permanent, but it makes the fish fly nicely ;-) )
00048         static const int sinvals[21] = 
00049                 {0, 156, 309, 454, 588, 705, 809, 891, 952, 987, 1000,
00050                  987, 952, 891, 809, 705, 588, 454, 309, 156, 0};
00051 
00052         Item *it = getItem(item_num);
00053 
00054         if (!it) {
00055                 // item gone
00056                 terminate();
00057                 return false;
00058         }
00059 
00060         sint32 x, y, z;
00061 
00062         currentpos += 1;
00063         if (currentpos > (2500/speed)) currentpos = (2500/speed);
00064 
00066         x = from_x + (((to_x - from_x) * currentpos) * speed) / 2500;
00067         y = from_y + (((to_y - from_y) * currentpos) * speed) / 2500;
00068         z = from_z + (((to_z - from_z) * currentpos) * speed) / 2500;
00069         if (curve) z += sinvals[(20*currentpos*speed)/2500]/25;
00070 
00071         it->collideMove(x,y,z,false,false);
00072 
00073         if (currentpos >= (2500/speed)) {
00074                 it->fall();
00075                 terminate();
00076         }
00077 
00078         return true;
00079 }
00080 
00081 void MissileProcess::saveData(ODataSource* ods)
00082 {
00083         Process::saveData(ods);
00084 
00085         ods->write4(static_cast<uint32>(from_x));
00086         ods->write4(static_cast<uint32>(from_y));
00087         ods->write4(static_cast<uint32>(from_z));
00088         ods->write4(static_cast<uint32>(to_x));
00089         ods->write4(static_cast<uint32>(to_y));
00090         ods->write4(static_cast<uint32>(to_z));
00091         ods->write4(static_cast<uint32>(speed));
00092         ods->write4(static_cast<uint32>(currentpos));
00093 
00094         uint8 c = (curve ? 1 : 0);
00095         ods->write1(c);
00096 
00097 }
00098 
00099 bool MissileProcess::loadData(IDataSource* ids, uint32 version)
00100 {
00101         if (!Process::loadData(ids, version)) return false;
00102 
00103         from_x = static_cast<int>(ids->read4());
00104         from_y = static_cast<int>(ids->read4());
00105         from_z = static_cast<int>(ids->read4());
00106         to_x = static_cast<int>(ids->read4());
00107         to_y = static_cast<int>(ids->read4());
00108         to_z = static_cast<int>(ids->read4());
00109         speed = static_cast<int>(ids->read4());
00110         currentpos = static_cast<int>(ids->read4());
00111 
00112         curve = (ids->read1() != 0);
00113 
00114         return true;
00115 }

Generated on Fri Jul 27 22:27:25 2007 for pentagram by  doxygen 1.4.7