00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
00036 DEFINE_RUNTIME_CLASSTYPE_CODE(MissileProcess,Process);
00037
00038 MissileProcess::MissileProcess()
00039 : Process()
00040 {
00041
00042 }
00043
00044 bool MissileProcess::run(const uint32 )
00045 {
00046
00047
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
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 }