- Visual C++源码
- Visual Basic源码
- C++ Builder源码
- Java源码
- Delphi源码
- C/C++源码
- PHP源码
- Perl源码
- Python源码
- Asm源码
- Pascal源码
- Borland C++源码
- Others源码
- SQL源码
- VBScript源码
- JavaScript源码
- ASP/ASPX源码
- C#源码
- Flash/ActionScript源码
- matlab源码
- PowerBuilder源码
- LabView源码
- Flex源码
- MathCAD源码
- VBA源码
- IDL源码
- Lisp/Scheme源码
- VHDL源码
- Objective-C源码
- Fortran源码
- tcl/tk源码
- QT源码
LANDSCPE.CPP
资源名称:tc3d.zip [点击查看]
上传用户:abcdshs
上传日期:2007-01-07
资源大小:1858k
文件大小:10k
源码类别:
游戏
开发平台:
Visual C++
- // (C) Copyright 1996 by Anthony J. Carin. All Rights Reserved.
- #include "stdafx.h"
- #include "gateway.h"
- #include "dudehold.h"
- #include "weaphold.h"
- #include "weapon.h"
- #include "antagon.h"
- #include "levels.h"
- #include "teleport.h"
- extern CString& getpath(CString& filename);
- landscape::landscape(CString& filename) : baseobject(filename)
- {
- m_type = LANDSCAPE;
- m_bmpfile = filename;
- m_LSEntry = 0;
- m_DeleteEntryAlso = FALSE;
- PrevLandScpe = 0;
- NextLandScpe = Game->Landscapes()->m_First;
- if (Game->Landscapes()->m_First)
- Game->Landscapes()->m_First->PrevLandScpe = this;
- Game->Landscapes()->m_First = this;
- }
- landscape::~landscape()
- {
- if (PrevLandScpe)
- PrevLandScpe->NextLandScpe = NextLandScpe;
- if (NextLandScpe)
- NextLandScpe->PrevLandScpe = PrevLandScpe;
- if (Game->Landscapes()->m_First == this)
- Game->Landscapes()->m_First = NextLandScpe;
- if (Game->Landscapes()->m_Curr == this)
- Game->Landscapes()->m_Curr = Game->Landscapes()->m_First;
- if (m_DeleteEntryAlso)
- {
- if (m_LSEntry == 0)
- m_LSEntry = Game->Landscapes()->GetLSEntry(location());
- delete m_LSEntry;
- }
- }
- void landscapelist::Purge()
- {
- landscape *TmpFirst = m_First;
- landscape *TmpCurr;
- while (TmpFirst)
- {
- TmpCurr = TmpFirst;
- TmpFirst = TmpFirst->NextLandScpe;
- delete m_Curr;
- }
- m_First = m_Curr = 0;
- }
- void landscapelist::load(CString& str)
- {
- Game->LevelPtr()->landscapemap = str;
- PurgeLandscape();
- FILE *fp;
- char tmpbuf[100];
- CString lobj;
- view tmpview;
- tccolor tmpcolor;
- fp = fopen((LPCSTR)Game->LevelPtr()->landscapemap, "r");
- if (fp <= 0)
- return;
- while (feof(fp) == 0)
- {
- fscanf(fp, "%s", tmpbuf);
- tmpview.setx((float)atof(tmpbuf));
- fscanf(fp, "%s", tmpbuf);
- tmpview.sety((float)atof(tmpbuf));
- fscanf(fp, "%s", tmpbuf);
- tmpview.setz((float)atof(tmpbuf));
- fscanf(fp, "%s", tmpbuf);
- tmpview.setxdir((short)atoi(tmpbuf));
- fscanf(fp, "%s", tmpbuf);
- tmpview.setydir((short)atoi(tmpbuf));
- fscanf(fp, "%s", tmpbuf);
- tmpview.setzdir((short)atoi(tmpbuf));
- fscanf(fp, "%s", tmpbuf);
- lobj = tmpbuf;
- fscanf(fp, "%s", tmpbuf);
- tmpcolor = (long)atol(tmpbuf);
- if (feof(fp) == 0)
- AddLSEntry(tmpview, lobj, tmpcolor);
- }
- fclose(fp);
- GotMap = TRUE;
- PauseCounter = 0;
- CreateCloseLandscapes();
- }
- void landscapelist::CreateCloseLandscapes()
- {
- if (!GotMap)
- return;
- if (--PauseCounter < 0)
- PauseCounter = 10;
- else
- return;
- landscape *tmpobj, *dtmpobj;
- LSEntryType *tmp = LSEntries;
- float dist;
- while (tmp)
- {
- tmpobj = 0;
- coordinate c = Game->Aim();
- dist = tmp->Location.distanceto(c);
- if (tmp->Created == FALSE &&
- dist <= VIEWRANGE)
- {
- tmp->Created = TRUE;
- CString Right = tmp->Image.Right(3);
- Right.MakeUpper();
- if (Right == (CString)"DUD")
- {
- long itmp = tmp->Color;
- #ifdef EDITOR
- if (itmp > 0)
- tmpobj = new dudeholder(tmp->Image);
- else
- {
- LSEntryType *savetmp = tmp;
- tmp = tmp->Next;
- delete savetmp;
- continue;
- }
- #else
- if (itmp > 0)
- {
- antagonist *anttmp;
- if (itmp > 10)
- {
- anttmp = new antagonist(tmp->Image, MALE);
- itmp -= 10;
- }
- else
- anttmp = new antagonist(tmp->Image, FEMALE);
- anttmp->setto(tmp->Location);
- anttmp->sethesitation((short) itmp);
- anttmp->shirtcolor(RGB(random(256), random(256), random(256)));
- anttmp->pantscolor(RGB(random(256), random(256), random(256)));
- Game->DrawQueue()->add(anttmp);
- LSEntryType *savetmp = tmp;
- tmp = tmp->Next;
- delete savetmp;
- continue;
- }
- else
- {
- tmpobj = new dudeholder(tmp->Image);
- tmpobj->setto(tmp->Location);
- tmpobj->setcolor(40);
- tmpobj->AssociatedLSEntry(tmp);
- Game->DrawQueue()->add(tmpobj);
- tmp = tmp->Next;
- continue;
- }
- #endif
- }
- if (Right == (CString)"MAP")
- tmpobj = new gateway(tmp->Image);
- else if (Right == (CString)"IMG")
- tmpobj = new landscape(tmp->Image);
- else if (Right == (CString)"TER") // Teleporter
- tmpobj = new Teleporter((short) tmp->Color);
- else if (Right == (CString)"PON") // Weapon
- {
- #ifdef EDITOR
- tmpobj = new weaponholder((WeaponType)(long)tmp->Color);
- #else
- WeaponType tmptype = (WeaponType)(long)tmp->Color;
- if (tmptype == SWORD)
- tmpobj = new weapon((CString)"sword.dat");
- else if (tmptype == SHIELD)
- tmpobj = new weapon((CString)"shield.dat");
- else
- tmpobj = new weapon((CString)"knife.dat");
- if (tmpobj->NoBody())
- {
- delete tmpobj;
- tmpobj = 0;
- }
- #endif
- }
- if (tmpobj)
- {
- tmpobj->setto(tmp->Location);
- if (Right == (CString)"PON") // Weapon
- tmpobj->setcolor(RGB(random(256), random(256), random(256)));
- else
- tmpobj->setcolor(tmp->Color);
- tmpobj->AssociatedLSEntry(tmp);
- Game->DrawQueue()->add(tmpobj);
- }
- }
- else if (tmp->Created == TRUE &&
- dist > VIEWRANGE)
- tmp->Created = FALSE;
- tmp = tmp->Next;
- }
- tmpobj = First();
- while (tmpobj)
- {
- dtmpobj = tmpobj;
- tmpobj = Next();
- coordinate c = Game->Aim();
- if (dtmpobj->location().distanceto(c) > VIEWRANGE)
- delete dtmpobj;
- }
- }
- LSEntryType * landscapelist::GetLSEntry(view& tmploc)
- {
- LSEntryType *tmp = LSEntries;
- while (tmp)
- {
- if (tmp->Location == tmploc)
- return tmp;
- tmp = tmp->Next;
- }
- return NULL;
- }
- void landscapelist::PurgeLandscape()
- {
- GotMap = FALSE;
- LSEntryType *tmp;
- while (LSEntries)
- {
- tmp = LSEntries;
- LSEntries = tmp->Next;
- delete tmp;
- }
- }
- void landscapelist::removeduplicates()
- {
- LSEntryType *tmp = LSEntries->Next;
- while (tmp)
- {
- if (*LSEntries == *tmp)
- {
- delete tmp;
- break;
- }
- tmp = tmp->Next;
- }
- }
- void landscapelist::AddLSEntry(view& v, CString& str, tccolor color)
- {
- LSEntryType *newls;
- newls = new LSEntryType(v, str, color);
- newls->Next = LSEntries;
- if (LSEntries)
- LSEntries->Prev = newls;
- LSEntries = newls;
- removeduplicates();
- }
- void landscapelist::AddLSEntry(baseobject *lnd)
- {
- if (lnd->IsGATEWAY())
- AddLSEntry(lnd->location(), ((gateway *)lnd)->mapfile(), lnd->getcolor());
- else if (lnd->IsLANDSCAPE())
- AddLSEntry(lnd->location(), ((landscape *)lnd)->bmpfile(), lnd->getcolor());
- else if (lnd->IsDUDEHOLDER())
- AddLSEntry(lnd->location(), ((dudeholder *)lnd)->dudename(), ((dudeholder *)lnd)->speed());
- else if (lnd->IsWEAPONHOLDER())
- AddLSEntry(lnd->location(), (CString)"WEAPON", ((weaponholder *)lnd)->NumType());
- else if (lnd->IsTELEPORTER())
- AddLSEntry(lnd->location(), (CString)"TELEPORTER", ((Teleporter *)lnd)->ToLevel());
- ((landscape *)lnd)->AssociatedLSEntry(LSEntries);
- }
- landscapelist::landscapelist()
- {
- m_First = 0;
- m_Curr = 0;
- GotMap = FALSE;
- LSEntries = 0;
- PauseCounter = 0;
- }
- LSEntryType::LSEntryType(view& v, CString& str, tccolor color)
- {
- Location = v;
- Image = str;
- Color = color;
- Created = FALSE;
- Prev = 0;
- }
- LSEntryType::~LSEntryType()
- {
- if (Next)
- Next->Prev = Prev;
- if (Prev)
- Prev->Next = Next;
- else
- Game->Landscapes()->LSEntries = Next;
- }
- char LSEntryType::operator ==(LSEntryType& other)
- {
- if (Location != other.Location)
- return FALSE;
- if (Image != other.Image)
- return FALSE;
- return TRUE;
- }
- void landscapelist::save()
- {
- if (Game->LevelPtr()->landscapemap.IsEmpty())
- return;
- FILE *fp;
- fp = fopen((LPCSTR)Game->LevelPtr()->landscapemap, "w");
- if (fp <= 0)
- return;
- view tmploc;
- LSEntryType *LStmp = LSEntries;
- while (LStmp)
- {
- tmploc = LStmp->Location;
- fprintf(fp, "%1.2f ", tmploc.x());
- fprintf(fp, "%1.2f ", tmploc.y());
- fprintf(fp, "%1.2f ", tmploc.z());
- fprintf(fp, "%d ", (short)tmploc.xdirection());
- fprintf(fp, "%d ", (short)tmploc.ydirection());
- fprintf(fp, "%d ", (short)tmploc.zdirection());
- fprintf(fp, "%s ", LStmp->Image);
- fprintf(fp, "%ldn", LStmp->Color);
- LStmp = LStmp->Next;
- }
- antagonist *atmp;
- atmp = (antagonist *)Game->DrawQueue()->first(ANTAGONIST);
- while (atmp)
- {
- tmploc = atmp->location();
- fprintf(fp, "%1.2f ", tmploc.x());
- fprintf(fp, "%1.2f ", tmploc.y());
- fprintf(fp, "%1.2f ", tmploc.z());
- fprintf(fp, "%d ", (short)tmploc.xdirection());
- fprintf(fp, "%d ", (short)tmploc.ydirection());
- fprintf(fp, "%d ", (short)tmploc.zdirection());
- fprintf(fp, "%s ", atmp->filepath());
- if (atmp->ismale() && atmp->skill() > 0)
- fprintf(fp, "%ldn", atmp->skill()+10);
- else
- fprintf(fp, "%ldn", atmp->skill());
- atmp = (antagonist *)Game->DrawQueue()->next(ANTAGONIST);
- }
- fclose(fp);
- }