00001 /* 00002 Copyright (C) 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 #include "pent_include.h" 00020 00021 #include "AvatarGravityProcess.h" 00022 #include "MainActor.h" 00023 #include "World.h" 00024 #include "GUIApp.h" 00025 #include "CurrentMap.h" 00026 #include "getObject.h" 00027 00028 #include "IDataSource.h" 00029 #include "ODataSource.h" 00030 00031 #include <cmath> 00032 00033 00034 // p_dynamic_cast stuff 00035 DEFINE_RUNTIME_CLASSTYPE_CODE(AvatarGravityProcess,GravityProcess); 00036 00037 AvatarGravityProcess::AvatarGravityProcess() 00038 : GravityProcess() 00039 { 00040 00041 } 00042 00043 AvatarGravityProcess::AvatarGravityProcess(MainActor* avatar, int gravity) 00044 : GravityProcess(avatar, gravity) 00045 { 00046 00047 } 00048 00049 bool AvatarGravityProcess::run(uint32 framenum) 00050 { 00051 if (!GUIApp::get_instance()->isMouseDown(BUTTON_RIGHT)) { 00052 // right mouse button not down, so fall normally 00053 00054 return GravityProcess::run(framenum); 00055 } 00056 00057 // right mouse button down, so see if we can cling to a ledge 00058 MainActor* avatar = getMainActor(); 00059 sint32 direction = avatar->getDir(); 00060 if (avatar->tryAnim(Animation::climb40, direction) == Animation::SUCCESS) { 00061 00062 // we can, so perform a hang animation 00063 // CHECKME: do we need to perform any other checks? 00064 00065 if (avatar->getLastAnim() != Animation::hang) 00066 avatar->doAnim(Animation::hang, 8); 00067 00068 return false; 00069 } else { 00070 00071 // fall normally 00072 return GravityProcess::run(framenum); 00073 } 00074 } 00075 00076 00077 void AvatarGravityProcess::saveData(ODataSource* ods) 00078 { 00079 GravityProcess::saveData(ods); 00080 } 00081 00082 bool AvatarGravityProcess::loadData(IDataSource* ids, uint32 version) 00083 { 00084 if (!GravityProcess::loadData(ids, version)) return false; 00085 00086 return true; 00087 }