00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
#include <stdincl.h>
00024
#include <math.h>
00025
#include <SDL_prim.h>
00026
00027
#include "defaults.h"
00028
#include "Main.h"
00029
#include "MenuDialog.h"
00030
#include "OptionsDialog.h"
00031
#include "LoginDialog.h"
00032
#include "PlayerDialog.h"
00033
#include "TextDialog.h"
00034
#include "Globals.h"
00035
#include "forms/Login.h"
00036
#include "commands/Say.h"
00037
#include "client.h"
00038
#include "TestMenu.h"
00039
#include "Player.h"
00040
#include "events/Map.h"
00041
#include "commands/Map.h"
00042
#include "ConnectThread.h"
00043
#include "Map.h"
00044
#include "DotCursor.h"
00045
#include "DotMenu.h"
00046
#include "MainWindow.h"
00047
00048
00049
#undef DEB
00050
#ifdef _DEBUG
00051
#define DEB(x) x
00052
#else
00053 #define DEB(x)
00054
#endif
00055
00056
00057 #define WARP 0
00058 #define GLOW 0.15
00059 #define GAP 2
00060 #define WIREFRAME
00061
00062
00063 Grid MainWindow::m_grid;
00064
00065
00066 MainWindow::MainWindow(SDLControl *pclControl)
00067 :gui::Surface(pclControl, 0 +
WARP, 0 +
WARP, pclControl -> GetScreen() -> w -
WARP * 2, pclControl -> GetScreen() -> h -
WARP * 2)
00068
00069
00070 #ifdef WIN32
00071 ,courier8("font.ttf", 15)
00072 #else
00073 ,courier8("../gui/fonts/font.ttf", 15)
00074 #endif
00075
00076 ,m_guiInput(this, 0, 455, 640, 25)
00077
00078 #ifdef USE_IMAGE
00079 ,m_image(SDL_LoadBMP("screenshots_big_7.bmp"))
00080 ,m_image_x(0)
00081 ,m_image_y(0)
00082 #endif
00083 ,m_pclMenuDialog(NULL)
00084 ,m_pclOptionsDialog(NULL)
00085 ,m_pclLoginDialog(NULL)
00086 ,m_pclPlayerDialog(NULL)
00087 ,m_pclTextDialog(NULL)
00088 ,m_pclConnectThread(NULL)
00089 ,m_pclTestMenu(NULL)
00090 ,m_dotMenu(NULL)
00091 ,m_test_v(90)
00092 ,m_test_v_vertikal(90)
00093 ,m_dot(NULL)
00094 ,m_dc(this,0,0)
00095 {
00096
00097
m_grid.
SetSize(pclControl -> GetScreen() -> w,pclControl -> GetScreen() -> h);
00098
m_grid.
SetBase( 50 );
00099
00100
00101
00102
00103
00104
00105 SetText(
"Main Window");
00106
00107
00108 SetBgColor(DEFAULT_BG_R,DEFAULT_BG_G,DEFAULT_BG_B);
00109 SetFgColor(DEFAULT_FG_R,DEFAULT_FG_G,DEFAULT_FG_B);
00110 SetTTFont(&
courier8);
00111 SetFrameWidth(0);
00112 SetFrameColor(DEFAULT_BG_R,DEFAULT_BG_G,DEFAULT_BG_B);
00113
00114
00115
00116
m_guiInput.SetBgColor( 255,255,255,0 );
00117
m_guiInput.SetFgColor( 0,0,0 );
00118
m_guiInput.SetFrameWidth(0);
00119
00120
m_dc.SetVisible(
false);
00121
00122
00123 AddChild(&
m_guiInput);
00124 AddChild(&
m_dc);
00125
00126
00127
00128
00129
00130
00131 SetAlpha(255);
00132 SetAlpha(SDL_ALPHA_OPAQUE,
false);
00133
#ifdef USE_IMAGE
00134
SDL_SetAlpha(m_image, SDL_RLEACCEL, SDL_ALPHA_OPAQUE);
00135
#endif
00136
}
00137
00138
00139 MainWindow::~MainWindow()
00140 {
00141
if (
m_pclMenuDialog)
00142 {
00143
delete m_pclMenuDialog;
00144 }
00145
if (
m_pclOptionsDialog)
00146 {
00147
delete m_pclOptionsDialog;
00148 }
00149
if (
m_pclLoginDialog)
00150 {
00151
delete m_pclLoginDialog;
00152 }
00153
if (
m_pclTextDialog)
00154 {
00155
delete m_pclTextDialog;
00156 }
00157
if (
m_pclConnectThread)
00158 {
00159
delete m_pclConnectThread;
00160 }
00161
if (
m_pclTestMenu)
00162 {
00163
delete m_pclTestMenu;
00164 }
00165
if (
m_dotMenu)
00166 {
00167
delete m_dotMenu;
00168 }
00169
while (
m_dots.size() > 0)
00170 {
00171 mapdots_t::iterator it =
m_dots.begin();
00172
MAPDOT *x = *it;
00173
m_dots.erase(it);
00174
delete x;
00175 }
00176 }
00177
00178
00179 void MainWindow::AddLine(
const string &str)
00180 {
00181
if (
m_pclTextDialog)
00182 {
00183
m_pclTextDialog ->
AddLine(str);
00184 }
00185 }
00186
00187
00188
#ifdef USE_IMAGE
00189
void MainWindow::MoveImage(
int xrel,
int yrel)
00190 {
00191
int b = m_grid.
GetBase();
00192
00193
00194
00195
00196
00197
00198
00199
00200 m_test_v_vertikal += yrel;
00201 m_test_v += xrel;
00202
00203
00204 InvalidateEv();
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216 }
00217
#endif
00218
00219
00220 void MainWindow::ShowMenu()
00221 {
00222
if (!
m_pclMenuDialog)
00223 {
00224
m_pclMenuDialog =
new MenuDialog(
this );
00225 AddChild(
m_pclMenuDialog);
00226 }
00227
else
00228 {
00229
m_pclMenuDialog -> SetVisible(
true);
00230
m_pclMenuDialog -> BringToTop();
00231 }
00232
m_pclMenuDialog -> Connected(
m_pclConnectThread ?
"Disconnect" :
"Connect");
00233
00234
m_pclMenuDialog -> InvalidateEv();
00235 }
00236
00237
00238 void MainWindow::ShowOptions()
00239 {
00240
if (!
m_pclOptionsDialog)
00241 {
00242
m_pclOptionsDialog =
new OptionsDialog(
this );
00243 AddChild(
m_pclOptionsDialog);
00244 }
00245
else
00246 {
00247
m_pclOptionsDialog -> SetVisible(
true);
00248
m_pclOptionsDialog -> BringToTop();
00249 }
00250
m_pclOptionsDialog -> UpdateData(
false);
00251
00252
m_pclOptionsDialog -> InvalidateEv();
00253 }
00254
00255
00256 void MainWindow::ShowLogin(Form::Form *pclForm)
00257 {
00258
if (!
m_pclLoginDialog)
00259 {
00260
m_pclLoginDialog =
new LoginDialog(
this );
00261 AddChild(
m_pclLoginDialog);
00262 }
00263
else
00264 {
00265
m_pclLoginDialog -> SetVisible(
true);
00266
m_pclLoginDialog -> BringToTop();
00267 }
00268
m_pclLoginDialog -> SetForm(pclForm);
00269
m_pclLoginDialog -> UpdateData(
false);
00270
00271
m_pclLoginDialog -> InvalidateEv();
00272 }
00273
00274
00275 void MainWindow::ShowPlayers(Form::Form *pclForm,vector<string> &players)
00276 {
00277 vector<string>::iterator it;
00278
if (!
m_pclPlayerDialog)
00279 {
00280
m_pclPlayerDialog =
new PlayerDialog(
this);
00281 AddChild(
m_pclPlayerDialog);
00282 }
00283
else
00284 {
00285
m_pclPlayerDialog -> SetVisible(
true);
00286
m_pclPlayerDialog -> BringToTop();
00287 }
00288
m_pclPlayerDialog -> SetForm(pclForm);
00289
m_pclPlayerDialog -> Clear();
00290
for (it = players.begin(); it != players.end(); it++)
00291 {
00292
m_pclPlayerDialog -> AddButton(*it);
00293 }
00294
00295
m_pclPlayerDialog -> InvalidateEv();
00296 }
00297
00298
00299 void MainWindow::ShowText()
00300 {
00301
if (!
m_pclTextDialog)
00302 {
00303
m_pclTextDialog =
new TextDialog(
this );
00304 AddChild(
m_pclTextDialog);
00305 }
00306
else
00307 {
00308
m_pclTextDialog -> SetVisible(
true);
00309
m_pclTextDialog -> BringToTop();
00310 }
00311
00312
m_pclTextDialog -> InvalidateEv();
00313 }
00314
00315
00316 void MainWindow::OnEvent(surface_event_t *pstEvent)
00317 {
00318
if (pstEvent -> type == GUI_EVENT_CLOSE)
00319 {
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
if (
m_pclLoginDialog && pstEvent ->
id ==
m_pclLoginDialog -> GetID())
00335 {
00336 Form::Form *pclForm =
m_pclLoginDialog -> GetForm();
00337
if (pclForm)
00338 {
00339
if (dynamic_cast<Form::Login *>(pclForm))
00340 {
00341
DEB( printf(
"SEND_LOGIN: pclForm is a Login\n");)
00342 }
00343
else
00344 {
00345
DEB( printf(
"SEND_LOGIN: pclForm is NOT a Login\n");)
00346 }
00347 }
00348
else
00349 {
00350
DEB( printf(
"SEND_LOGIN: pclForm is NULL\n");)
00351 }
00352
if (
m_pclConnectThread)
00353 {
00354
DEB( printf(
"SEND_LOGIN: BufMessage()\n");)
00355
m_pclConnectThread -> BufMessage(pclForm);
00356 }
00357
else
00358 {
00359
DEB( printf(
"SEND_LOGIN: m_pclConnectThread is NULL\n");)
00360 }
00361
m_pclLoginDialog -> SetVisible(
false);
00362
m_pclLoginDialog -> InvalidateEv();
00363 }
00364
else
00365
if (
m_pclPlayerDialog && pstEvent ->
id ==
m_pclPlayerDialog -> GetID())
00366 {
00367
if (
m_pclConnectThread)
00368 {
00369 Form::Form *pclForm =
m_pclPlayerDialog -> GetForm();
00370
m_pclConnectThread -> BufMessage(pclForm);
00371 }
00372
m_pclPlayerDialog -> SetVisible(
false);
00373
m_pclPlayerDialog -> InvalidateEv();
00374 }
00375
else
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390 {
00391
00392
for (surfacevector_t::iterator it = m_ChildList.begin(); it != m_ChildList.end(); it++)
00393 {
00394
if (pstEvent ->
id == (*it) -> GetID())
00395 {
00396 (*it) -> SetVisible(
false);
00397 (*it) -> InvalidateEv();
00398 }
00399 }
00400 }
00401 }
00402
else
00403
if (pstEvent -> type == GUI_EVENT_EDIT)
00404 {
00405
if (pstEvent ->
id ==
m_guiInput.GetID())
00406 {
00407
if (
m_pclConnectThread)
00408 {
00409 Command::Say cmd(
m_guiInput.GetLine());
00410
m_pclConnectThread -> BufMessage(&cmd);
00411 }
00412
DEB(printf(
"Input: '%s'\n",
m_guiInput.GetLine());)
00413
m_guiInput.SetLine(
"");
00414
m_guiInput.InvalidateEv();
00415 }
00416 }
00417 }
00418
00419
00420 void MainWindow::OnMouseMove(coord_t x,coord_t y,coord_t xrel,coord_t yrel)
00421 {
00422
00423 mapdots_t::iterator it;
00424
MAPDOT *dot = NULL;
00425
00426
for (it =
m_dots.begin(); it !=
m_dots.end(); it++)
00427 {
00428
MAPDOT *d = *it;
00429
long xx = abs(d -> x - x);
00430
long yy = abs(d -> y - y);
00431
if (xx < 10 && yy < 10)
00432 {
00433 dot = d;
00434 }
00435 }
00436
if (dot !=
m_dot)
00437 {
00438
if (
m_dc.IsVisible())
00439 {
00440 SDL_Rect a =
m_dc.GetAbsoluteRect();
00441 InvalidateRectEv(a);
00442 }
00443 }
00444
m_dot = dot;
00445
if (
m_dot)
00446 {
00447
m_dc.MoveTo(
this,
m_dot -> x - 5,
m_dot -> y - 5);
00448 }
00449
else
00450 {
00451
m_dc.MoveTo(
this, 0, 0,
false);
00452 }
00453
if (dot)
00454 {
00455
m_dot = dot;
00456
m_dc.SetX(
m_dot -> x - 5);
00457
m_dc.SetY(
m_dot -> y - 5);
00458
m_dc.GetParent() -> CalculateAbsolute();
00459
m_dc.SetVisible(
true);
00460
m_dc.InvalidateEv();
00461 }
00462
else
00463 {
00464
m_dot = dot;
00465
m_dc.SetVisible(
false);
00466 }
00467 }
00468
00469
00470 void MainWindow::OnRightClick(coord_t x,coord_t y)
00471 {
00472
if (
m_dot)
00473 {
00474
if (!
m_dotMenu)
00475 {
00476
m_dotMenu =
new DotMenu(
this );
00477
m_dotMenu -> SetX(
m_dot -> x );
00478
m_dotMenu -> SetY(
m_dot -> y );
00479 AddChild(
m_dotMenu);
00480
m_dotMenu -> InvalidateEv();
00481
m_dc.Bond(
m_dotMenu );
00482 }
00483
else
00484 {
00485
if (
m_dotMenu -> IsVisible())
00486 {
00487 SDL_Rect a =
m_dotMenu -> GetAbsoluteRect();
00488 InvalidateRectEv(a);
00489 }
00490
else
00491 {
00492
m_dotMenu -> SetVisible(
true);
00493 }
00494
m_dotMenu -> SetX(
m_dot -> x );
00495
m_dotMenu -> SetY(
m_dot -> y );
00496 CalculateAbsolute();
00497
m_dotMenu -> InvalidateEv();
00498 }
00499 }
00500
else
00501 {
00502
if (!
m_pclTestMenu)
00503 {
00504
m_pclTestMenu =
new TestMenu(
this );
00505
m_pclTestMenu -> SetX( x );
00506
m_pclTestMenu -> SetY( y );
00507 AddChild(
m_pclTestMenu);
00508
m_pclTestMenu -> InvalidateEv();
00509 }
00510
else
00511 {
00512
if (
m_pclTestMenu -> IsVisible())
00513 {
00514 SDL_Rect a =
m_pclTestMenu -> GetAbsoluteRect();
00515 InvalidateRectEv(a);
00516 }
00517
else
00518 {
00519
m_pclTestMenu -> SetVisible(
true);
00520 }
00521
m_pclTestMenu -> SetX( x );
00522
m_pclTestMenu -> SetY( y );
00523 CalculateAbsolute();
00524
m_pclTestMenu -> InvalidateEv();
00525 }
00526 }
00527 }
00528
00529
00530 void MainWindow::Connect()
00531 {
00532
if (
m_pclConnectThread)
00533 {
00534 printf(
"Already connected - disconnecting...\n");
00535
Disconnect();
00536
return;
00537 }
00538
if (!
m_pclConnectThread)
00539 {
00540 printf(
"Creating connect thread\n");
00541
m_pclConnectThread =
new ConnectThread( (
char *)Globals::m_host.c_str(), Globals::m_port);
00542 }
00543
else
00544 {
00545
pprintf(
"Already connected.\n");
00546 }
00547 }
00548
00549
00550 void MainWindow::Disconnect()
00551 {
00552
if (
m_pclConnectThread)
00553 {
00554 printf(
"Deleteing connect thread\n");
00555
m_pclConnectThread -> SetRunning(
false);
00556 SDL_Delay(1000);
00557
delete m_pclConnectThread;
00558
m_pclConnectThread = NULL;
00559 }
00560
else
00561 {
00562
pprintf(
"Not connected.\n");
00563 }
00564 }
00565
00566
00567 Surface *
MainWindow::GetInput()
00568 {
00569
return &
m_guiInput;
00570 }
00571
00572
00573 void MainWindow::SetAngles(
double a1,
double a2)
00574 {
00575
m_test_v = a1;
00576
m_test_v_vertikal = a2;
00577
00578
00579
00580 SetDirty(
true);
00581 }
00582
00583
00584 void MainWindow::IncreaseBase()
00585 {
00586
int b =
m_grid.
GetBase();
00587
00588 b++;
00589
m_grid.
SetBase(b);
00590
00591
00592
00593 SetDirty(
true);
00594 }
00595
00596
00597 void MainWindow::DecreaseBase()
00598 {
00599
int b =
m_grid.
GetBase();
00600
00601 b--;
00602
if (b > 0)
00603 {
00604
m_grid.
SetBase(b);
00605 }
00606
00607
00608
00609 SetDirty(
true);
00610 }
00611
00612
00613 void MainWindow::Redraw()
00614 {
00615
00616
00617 SetDirty(
true);
00618 }
00619
00620
00621
#ifdef USE_IMAGE
00622
void MainWindow::Draw()
00623 {
00624 SDL_Rect src;
00625 SDL_Rect dst;
00626 SDLControl *pcl = GetSDLControl();
00627
00628 src.w = dst.w = pcl -> GetScreen() -> w;
00629 src.h = dst.h = pcl -> GetScreen() -> h;
00630 src.x = m_image_x;
00631 src.y = m_image_y;
00632 dst.x = 0;
00633 dst.y = 0;
00634 SDL_BlitSurface(m_image, &src, m_screen, &dst);
00635 }
00636
#endif
00637
00638
00639 void MainWindow::Draw()
00640 {
00641
#pragma warning("remember to reset m_self when disconnected from server")
00642
#pragma warning("and player cache")
00643
#pragma warning("and map cache")
00644
#pragma warning("etc etc cache")
00645
Player *
self = NULL;
00646
00647 printf(
"MainWindow::Draw()\n");
00648
if (!
m_pclConnectThread || (
self =
m_pclConnectThread -> GetSelf()) == NULL)
00649 {
00650 printf(
"Not drawing background, because..\n");
00651
if (!
m_pclConnectThread)
00652 {
00653 printf(
" * not connected\n");
00654 }
00655
else
00656
if (!
self)
00657 {
00658 printf(
" * self is NULL\n");
00659 }
00660 SDL_FillRect(GetScreen(), GetClientRectPtr(), SDL_MapRGB(GetScreen() -> format, 224, 224, 192));
00661
return;
00662 }
00663
else
00664 {
00665 printf(
"Drawing background!\n");
00666 }
00667
00668
long xpos =
self -> GetX();
00669
long ypos =
self -> GetY();
00670
#define CHUNKSIZE MAPSIZE
00671
long chunkx = xpos /
CHUNKSIZE;
00672
long chunky = ypos /
CHUNKSIZE;
00673
for (
long x = chunkx - 1; x <= chunkx + 1; x++)
00674 {
00675
long cx = x *
CHUNKSIZE;
00676
for (
long y = chunky - 1; y <= chunky + 1; y++)
00677 {
00678
long cy = y *
CHUNKSIZE;
00679
Map *map =
m_pclConnectThread -> GetMap(cx, cy);
00680 printf(
" . map @ [%ld,%ld] is %s\n",cx,cy,map ?
"ok" :
"NULL");
00681
if (!map)
00682 {
00683
00684 Command::Map cmd(cx,cy,0);
00685
m_pclConnectThread -> BufMessage(&cmd);
00686
00687
00688 printf(
"adding empty section\n");
00689 fflush(stdout);
00690
m_pclConnectThread -> AddMap(cx, cy);
00691
#pragma warning("how to re-request this section if we don't get it?")
00692
}
00693
else
00694 {
00695
00696 }
00697 }
00698 }
00699
00700 printf(
" * done requesting map parts\n");
00701
00702 {
00703
#ifdef WIREFRAME
00704
Uint32 color = GetFgColor();
00705
#endif
00706
Uint32 light;
00707
int w =
m_grid.
GetWidth() / 2 + 2;
00708
int h =
m_grid.
GetHeight() / 2 + 2;
00709
double base =
m_grid.
GetBase();
00710
double hbase =
m_grid.
GetHBase();
00711
int xpos1;
00712
int ypos1;
00713
int xpos2;
00714
int ypos2;
00715
int xpos3;
00716
int ypos3;
00717
int xpos4;
00718
int ypos4;
00719
int h1;
00720
int h2;
00721
int h3;
00722
int h4;
00723
double dh1,dh2,dh3,dh4;
00724
double hmitt;
00725
00726
00727
double r;
00728
double v;
00729
double aa;
00730
00731
00732
double r_vertikal;
00733
double v_vertikal;
00734
double aa_vertikal;
00735
00736
double aa2;
00737
double aa2_vertikal;
00738
00739
if (SDL_MUSTLOCK(m_screen))
00740 {
00741 SDL_LockSurface(m_screen);
00742 }
00743
00744 SDL_FillRect(m_screen, GetClientRectPtr(), GetBgColor());
00745
00746
00747
00748
00749
00750
00751
00752
while (
m_dots.size() > 0)
00753 {
00754 mapdots_t::iterator it =
m_dots.begin();
00755
MAPDOT *x = *it;
00756
m_dots.erase(it);
00757
delete x;
00758 }
00759
m_dot = NULL;
00760
m_dc.SetVisible(
false);
00761
m_dc.InvalidateEv();
00762
00763
for (
int y = -h; y <= h; y++)
00764 {
00765
long cy = ypos + y;
00766
00767
for (
int x = -w; x <= w; x++)
00768 {
00769
long cx = xpos + x;
00770
00771
m_grid.
GetXY(x,y,&xpos1,&ypos1,&h1);
00772 h1 =
Get_h(cx,cy);
00773 ypos1 += h1;
00774 dh1 = h1;
00775 {
00776
MAPDOT *dot =
new MAPDOT;
00777 dot -> x = xpos1;
00778 dot -> y = ypos1;
00779 dot -> cx = cx;
00780 dot -> cy = cy;
00781
m_dots.insert(
m_dots.end(), dot);
00782 }
00783
00784
if (y % 2)
00785 {
00786
m_grid.
GetXY(x,y - 1,&xpos2,&ypos2,&h2);
00787 h2 = Get_h(cx,cy - 1);
00788 }
00789
else
00790 {
00791
m_grid.
GetXY(x - 1,y - 1,&xpos2,&ypos2,&h2);
00792 h2 = Get_h(cx - 1,cy - 1);
00793 }
00794 ypos2 += h2;
00795 dh2 = h2;
00796
00798
00799
00800
00801
if (y % 2)
00802 {
00803
m_grid.
GetXY(x - 1,y,&xpos3,&ypos3,&h3);
00804 h3 = Get_h(cx - 1,cy);
00805 }
00806
else
00807 {
00808
m_grid.
GetXY(x - 1,y,&xpos3,&ypos3,&h3);
00809 h3 = Get_h(cx - 1,cy);
00810 }
00811 ypos3 += h3;
00812 dh3 = h3;
00813
00814
00815
if (h3 > h1)
00816 {
00817 r = atan((dh3 - dh1) / base);
00818 v = 360 * r / (2 * M_PI);
00819 }
00820
else
00821
if (h3 < h1)
00822 {
00823 r = -atan((dh1 - dh3) / base);
00824 v = 360 * r / (2 * M_PI);
00825 }
00826
else
00827 {
00828 r = 0;
00829 v = 0;
00830 }
00831
00832 hmitt = (dh2 + dh3) / 2;
00833
if (hmitt > h2)
00834 {
00835 r_vertikal = atan((hmitt - dh2) / hbase);
00836 v_vertikal = 360 * r_vertikal / (2 * M_PI);
00837 }
00838
else
00839
if (hmitt < h2)
00840 {
00841 r_vertikal = -atan((dh2 - hmitt) / hbase);
00842 v_vertikal = 360 * r_vertikal / (2 * M_PI);
00843 }
00844
else
00845 {
00846 r_vertikal = 0;
00847 v_vertikal = 0;
00848 }
00849
00850 aa =
m_grid.
Sin(
m_test_v + v);
00851 aa2 =
m_grid.
Sin(90 + v_vertikal);
00852 aa_vertikal =
m_grid.
Sin(
m_test_v_vertikal + v_vertikal);
00853 aa2_vertikal =
m_grid.
Sin(90 + v);
00854
00855
if (aa <
GLOW)
00856 {
00857 aa =
GLOW;
00858 }
00859
if (aa_vertikal <
GLOW)
00860 {
00861 aa_vertikal =
GLOW;
00862 }
00863 light = SDL_MapRGB(m_screen -> format,
00864 0,
00865 (
int)(255 * aa * aa2 * aa_vertikal * aa2_vertikal),
00866 0);
00867
00868
#ifdef WIREFRAME
00869
SDL_drawLine(m_screen, xpos1, ypos1, xpos2, ypos2, color);
00870 SDL_drawLine(m_screen, xpos1, ypos1, xpos3, ypos3, color);
00871 SDL_drawLine(m_screen, xpos2, ypos2, xpos3, ypos3, color);
00872
#else
00873
SDL_fillTriangle(m_screen, xpos1-
GAP, ypos1-
GAP, xpos2, ypos2+
GAP, xpos3+
GAP, ypos3-
GAP, light);
00874
#endif
00875
00877
00878
00879
00880
if (y % 2)
00881 {
00882
m_grid.
GetXY(x + 1,y - 1,&xpos4,&ypos4,&h4);
00883 h4 = Get_h(cx + 1,cy - 1);
00884 }
00885
else
00886 {
00887
m_grid.
GetXY(x,y - 1,&xpos4,&ypos4,&h4);
00888 h4 = Get_h(cx, cy - 1);
00889 }
00890 ypos4 += h4;
00891 dh4 = h4;
00892
00893
00894
if (h2 > h4)
00895 {
00896 r = atan((dh2 - dh4) / base);
00897 v = 360 * r / (2 * M_PI);
00898 }
00899
else
00900
if (h2 < h4)
00901 {
00902 r = -atan((dh4 - dh2) / base);
00903 v = 360 * r / (2 * M_PI);
00904 }
00905
else
00906 {
00907 r = 0;
00908 v = 0;
00909 }
00910
00911 hmitt = (dh2 + dh4) / 2;
00912
if (hmitt > h1)
00913 {
00914 r_vertikal = -atan((hmitt - dh1) / hbase);
00915 v_vertikal = 360 * r_vertikal / (2 * M_PI);
00916 }
00917
else
00918
if (hmitt < h1)
00919 {
00920 r_vertikal = atan((dh1 - hmitt) / hbase);
00921 v_vertikal = 360 * r_vertikal / (2 * M_PI);
00922 }
00923
else
00924 {
00925 r_vertikal = 0;
00926 v_vertikal = 0;
00927 }
00928
00929 aa =
m_grid.
Sin(
m_test_v + v);
00930 aa2 =
m_grid.
Sin(90 + v_vertikal);
00931 aa_vertikal =
m_grid.
Sin(
m_test_v_vertikal + v_vertikal);
00932 aa2_vertikal =
m_grid.
Sin(90 + v);
00933
00934
if (aa <
GLOW)
00935 {
00936 aa =
GLOW;
00937 }
00938
if (aa_vertikal <
GLOW)
00939 {
00940 aa_vertikal =
GLOW;
00941 }
00942 light = SDL_MapRGB(m_screen -> format,
00943 0,
00944 (
int)(255 * aa * aa2 * aa_vertikal * aa2_vertikal),
00945 0);
00946
#ifdef WIREFRAME
00947
SDL_drawLine(m_screen, xpos1, ypos1, xpos2, ypos2, color);
00948 SDL_drawLine(m_screen, xpos1, ypos1, xpos4, ypos4, color);
00949 SDL_drawLine(m_screen, xpos2, ypos2, xpos4, ypos4, color);
00950
#else
00951
SDL_fillTriangle(m_screen, xpos1, ypos1-
GAP, xpos2+
GAP, ypos2+
GAP, xpos4-
GAP, ypos4+
GAP, light);
00952
#endif
00953
00954 }
00955 }
00956
for (mapdots_t::iterator it =
m_dots.begin(); it !=
m_dots.end(); it++)
00957 {
00958
MAPDOT *dot = *it;
00959
00960
00961
#ifdef WIREFRAME
00962
SDL_fillCircle(m_screen, dot -> x, dot -> y, 2, SDL_MapRGB(m_screen -> format, 255, 255, 255));
00963
#endif
00964
}
00965
if (SDL_MUSTLOCK(m_screen))
00966 {
00967 SDL_UnlockSurface(m_screen);
00968 }
00969 }
00970 }
00971
00972
00973 int MainWindow::Get_h(
long x,
long y)
00974 {
00975
Map *map =
m_pclConnectThread -> GetMap(x,y);
00976
return map ? map ->
Get_h(x,y) : 0;
00977 }
00978
00979
00980 int MainWindow::Get_t_left(
long x,
long y)
00981 {
00982
Map *map =
m_pclConnectThread -> GetMap(x,y);
00983
return map ->
Get_t_left(x,y);
00984 }
00985
00986
00987 int MainWindow::Get_t_up(
long x,
long y)
00988 {
00989
Map *map =
m_pclConnectThread -> GetMap(x,y);
00990
return map ->
Get_t_up(x,y);
00991 }
00992
00993