summaryrefslogtreecommitdiffstats
path: root/src/target.cpp
diff options
context:
space:
mode:
authoradiblol <adiblol@1tbps.org>2012-03-08 19:32:05 +0100
committeradiblol <adiblol@1tbps.org>2012-03-08 19:32:05 +0100
commita4c804b49ec872b71bd5a0167c3ad45704a3cc30 (patch)
tree8c931235247d662ca46a99695beb328fdfc8e8a8 /src/target.cpp
downloadcolobot-a4c804b49ec872b71bd5a0167c3ad45704a3cc30.tar.gz
colobot-a4c804b49ec872b71bd5a0167c3ad45704a3cc30.tar.bz2
colobot-a4c804b49ec872b71bd5a0167c3ad45704a3cc30.zip
Initial commit, Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
Diffstat (limited to 'src/target.cpp')
-rw-r--r--src/target.cpp271
1 files changed, 271 insertions, 0 deletions
diff --git a/src/target.cpp b/src/target.cpp
new file mode 100644
index 0000000..b0b64c2
--- /dev/null
+++ b/src/target.cpp
@@ -0,0 +1,271 @@
+// target.cpp
+
+#define STRICT
+#define D3D_OVERLOADS
+
+#include <windows.h>
+#include <stdio.h>
+#include <d3d.h>
+
+#include "struct.h"
+#include "D3DEngine.h"
+#include "math3d.h"
+#include "event.h"
+#include "misc.h"
+#include "iman.h"
+#include "robotmain.h"
+#include "object.h"
+#include "restext.h"
+#include "target.h"
+
+
+
+
+// Constructeur de l'objet.
+
+CTarget::CTarget(CInstanceManager* iMan) : CControl(iMan)
+{
+ CControl::CControl(iMan);
+}
+
+// Destructeur de l'objet.
+
+CTarget::~CTarget()
+{
+ CControl::~CControl();
+}
+
+
+// Crée un nouveau bouton.
+
+BOOL CTarget::Create(FPOINT pos, FPOINT dim, int icon, EventMsg eventMsg)
+{
+ if ( eventMsg == EVENT_NULL ) eventMsg = GetUniqueEventMsg();
+
+ CControl::Create(pos, dim, icon, eventMsg);
+
+ return TRUE;
+}
+
+
+// Gestion d'un événement.
+
+BOOL CTarget::EventProcess(const Event &event)
+{
+#if 0
+ if ( (m_state & STATE_VISIBLE) == 0 ) return TRUE;
+ if ( m_state & STATE_DEAD ) return TRUE;
+
+ CControl::EventProcess(event);
+
+ if ( event.event == EVENT_MOUSEMOVE )
+ {
+ if ( CControl::Detect(event.pos) )
+ {
+ m_engine->SetMouseType(D3DMOUSETARGET);
+ Event newEvent = event;
+ newEvent.event = m_eventMsg;
+ m_event->AddEvent(newEvent);
+ return FALSE;
+ }
+ }
+
+ if ( event.event == EVENT_LBUTTONDOWN &&
+ (m_state & STATE_VISIBLE) &&
+ (m_state & STATE_ENABLE) )
+ {
+ if ( CControl::Detect(event.pos) )
+ {
+ Event newEvent = event;
+ newEvent.event = EVENT_OBJECT_FIRE;
+ m_event->AddEvent(newEvent);
+ return FALSE;
+ }
+ }
+
+ return TRUE;
+#else
+ CObject* pObj;
+
+ if ( (m_state & STATE_VISIBLE) == 0 ) return TRUE;
+ if ( m_state & STATE_DEAD ) return TRUE;
+
+ CControl::EventProcess(event);
+
+ if ( event.event == EVENT_MOUSEMOVE )
+ {
+ m_main->SetFriendAim(FALSE);
+
+ if ( CControl::Detect(event.pos) )
+ {
+ pObj = DetectFriendObject(event.pos);
+ if ( pObj == 0 )
+ {
+ m_engine->SetMouseType(D3DMOUSETARGET);
+
+ Event newEvent = event;
+ newEvent.event = m_eventMsg;
+ m_event->AddEvent(newEvent);
+ return FALSE;
+ }
+ else
+ {
+ m_main->SetFriendAim(TRUE);
+ m_engine->SetMouseType(D3DMOUSENORM);
+ }
+ }
+ }
+
+ if ( event.event == EVENT_LBUTTONDOWN &&
+ (m_state & STATE_VISIBLE) &&
+ (m_state & STATE_ENABLE) )
+ {
+ if ( CControl::Detect(event.pos) )
+ {
+ if ( !m_main->RetFriendAim() )
+ {
+ Event newEvent = event;
+ newEvent.event = EVENT_OBJECT_FIRE;
+ m_event->AddEvent(newEvent);
+ return FALSE;
+ }
+ }
+ }
+
+ return TRUE;
+#endif
+}
+
+
+// Dessine le bouton.
+
+void CTarget::Draw()
+{
+ // C'est totalement invisible !
+}
+
+
+// Retourne le tooltip.
+
+BOOL CTarget::GetTooltip(FPOINT pos, char* name)
+{
+#if 0
+ if ( (m_state&STATE_VISIBLE) && Detect(pos) ) // dans la fenêtre ?
+ {
+ strcpy(name, m_tooltip);
+ return TRUE; // ne détecte pas les objets dessous !
+ }
+
+ return FALSE;
+#else
+//? CObject* pObj;
+
+ if ( (m_state & STATE_VISIBLE) == 0 ) return FALSE;
+
+ if ( (m_state&STATE_VISIBLE) && Detect(pos) ) // dans la fenêtre ?
+ {
+//? pObj = DetectFriendObject(pos);
+//? if ( pObj == 0 )
+ if ( !m_main->RetFriendAim() )
+ {
+ strcpy(name, m_tooltip);
+ return TRUE; // ne détecte pas les objets dessous !
+ }
+ }
+
+ return FALSE;
+#endif
+}
+
+
+// Détecte l'objet visé par la souris.
+
+CObject* CTarget::DetectFriendObject(FPOINT pos)
+{
+ ObjectType type;
+ CObject *pObj, *pTarget;
+ int objRank, i, j, rank;
+
+ objRank = m_engine->DetectObject(pos);
+
+ for ( i=0 ; i<1000000 ; i++ )
+ {
+ pObj = (CObject*)m_iMan->SearchInstance(CLASS_OBJECT, i);
+ if ( pObj == 0 ) break;
+
+ if ( !pObj->RetActif() ) continue;
+ if ( pObj->RetProxyActivate() ) continue;
+ if ( pObj->RetSelect() ) continue;
+
+ pTarget = 0;
+ type = pObj->RetType();
+ if ( type == OBJECT_DERRICK ||
+ type == OBJECT_FACTORY ||
+ type == OBJECT_REPAIR ||
+ type == OBJECT_DESTROYER ||
+ type == OBJECT_STATION ||
+ type == OBJECT_CONVERT ||
+ type == OBJECT_TOWER ||
+ type == OBJECT_RESEARCH ||
+ type == OBJECT_RADAR ||
+ type == OBJECT_INFO ||
+ type == OBJECT_ENERGY ||
+ type == OBJECT_LABO ||
+ type == OBJECT_NUCLEAR ||
+ type == OBJECT_PARA ||
+ type == OBJECT_SAFE ||
+ type == OBJECT_HUSTON ||
+ type == OBJECT_HUMAN ||
+ type == OBJECT_TECH ||
+ type == OBJECT_TOTO ||
+ type == OBJECT_MOBILEfa ||
+ type == OBJECT_MOBILEta ||
+ type == OBJECT_MOBILEwa ||
+ type == OBJECT_MOBILEia ||
+ type == OBJECT_MOBILEfc ||
+ type == OBJECT_MOBILEtc ||
+ type == OBJECT_MOBILEwc ||
+ type == OBJECT_MOBILEic ||
+ type == OBJECT_MOBILEfi ||
+ type == OBJECT_MOBILEti ||
+ type == OBJECT_MOBILEwi ||
+ type == OBJECT_MOBILEii ||
+ type == OBJECT_MOBILEfs ||
+ type == OBJECT_MOBILEts ||
+ type == OBJECT_MOBILEws ||
+ type == OBJECT_MOBILEis ||
+ type == OBJECT_MOBILErt ||
+ type == OBJECT_MOBILErc ||
+ type == OBJECT_MOBILErr ||
+ type == OBJECT_MOBILErs ||
+ type == OBJECT_MOBILEsa ||
+ type == OBJECT_MOBILEft ||
+ type == OBJECT_MOBILEtt ||
+ type == OBJECT_MOBILEwt ||
+ type == OBJECT_MOBILEit ||
+ type == OBJECT_MOBILEdr )
+ {
+ pTarget = pObj;
+ }
+ else if ( (type == OBJECT_POWER ||
+ type == OBJECT_ATOMIC ) &&
+ pObj->RetTruck() != 0 ) // pile utilisée ?
+ {
+ pTarget = pObj->RetTruck();
+ if ( pTarget->RetType() == OBJECT_MOBILEtg )
+ {
+ pTarget = 0;
+ }
+ }
+
+ for ( j=0 ; j<OBJECTMAXPART ; j++ )
+ {
+ rank = pObj->RetObjectRank(j);
+ if ( rank == -1 ) continue;
+ if ( rank != objRank ) continue;
+ return pTarget;
+ }
+ }
+ return 0;
+}
+