00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "Move.h"
00021 #include "InSocket.h"
00022 #include "Player.h"
00023 #include "Chunk.h"
00024 #include "Look.h"
00025 #include "Terrain.h"
00026 #include "Area.h"
00027
00028
00029 void Move::move_to(InSocket *from,Chunk& north,int ny_x,int ny_y,bool hide_map)
00030 {
00031 Database& db = from -> GetDatabase();
00032 Player pl(db, from -> GetAccountName());
00033 Area area(db, pl.GetArea());
00034 Terrain t(db, area, north.Get(ny_x, ny_y));
00035 if ((t.Exists() && !t.IsImpassable()) || pl.IsWizard())
00036 {
00037 pl.SetChunk(north.GetNum());
00038 pl.SetChunkX(ny_x);
00039 pl.SetChunkY(ny_y);
00041 if (m_loc_y < 0)
00042 pl.SetFacing(1);
00043 if (m_loc_y > 0)
00044 pl.SetFacing(2);
00045 if (m_loc_x > 0)
00046 pl.SetFacing(3);
00047 if (m_loc_x < 0)
00048 pl.SetFacing(4);
00049 if (!hide_map)
00050 Look::LookMap(from);
00051 Look::Show(from);
00052 from -> SetMoveEvent(0, 1000);
00053 }
00054 else
00055 {
00056 from -> Send("Impassable terrain ahead.\n");
00057 from -> CancelMoves();
00058 }
00059 from -> SetPrompt();
00060 }
00061
00062
00063 void Move::try_move(InSocket *from, int ch_x, int ch_y, int ch_z, bool hide_map)
00064 {
00065 Database& db = from -> GetDatabase();
00066 Player pl(db, from -> GetAccountName());
00067 Area area(db, pl.GetArea());
00068 Chunk chunk(db, area, pl.GetChunk());
00069
00070 int ny_x = pl.GetChunkX() + m_loc_x;
00071 int ny_y = pl.GetChunkY() + m_loc_y;
00072 if (!ch_z && ny_x >= 0 && ny_x < area.GetWidth() && ny_y >= 0 && ny_y < area.GetHeight())
00073 {
00074 move_to(from, chunk, ny_x, ny_y, hide_map);
00075 }
00076 else
00077 {
00078 if (ch_z && !pl.IsWizard())
00079 {
00080 Terrain t(db, area, chunk.Get(ny_x, ny_y));
00081 if ((ch_z == 1 && t.GetChar() != 'U') || (ch_z == -1 && t.GetChar() != 'D'))
00082 {
00083 from -> Send("No exit that way.\n");
00084 from -> CancelMoves();
00085 from -> SetPrompt();
00086 return;
00087 }
00088 }
00089 Chunk north(db, area, chunk.GetX() + ch_x, chunk.GetY() + ch_y, chunk.GetZ() + ch_z);
00090 if (north.Exists())
00091 {
00092 while (ny_x < 0)
00093 ny_x += area.GetWidth();
00094 while (ny_y < 0)
00095 ny_y += area.GetHeight();
00096 while (ny_x >= area.GetWidth())
00097 ny_x -= area.GetWidth();
00098 while (ny_y >= area.GetHeight())
00099 ny_y -= area.GetHeight();
00100 move_to(from, north, ny_x, ny_y, hide_map);
00101 }
00102 else
00103 if (pl.IsWizard())
00104 {
00105 from -> SetPrompt(this, 0, "Create a new chunk of land (y/N)? ");
00106 from -> CancelMoves();
00107 }
00108 else
00109 {
00110 from -> Send("End of the world.\n");
00111 from -> CancelMoves();
00112 from -> SetPrompt();
00113 }
00114 }
00115 }
00116
00117
00118 void Move::try_create(InSocket *from,const std::string& line,int ch_x,int ch_y,int ch_z)
00119 {
00120 Database& db = from -> GetDatabase();
00121 Player pl(from -> GetDatabase(), from -> GetAccountName());
00122 Area area(db, pl.GetArea());
00123 Chunk chunk(db, area, pl.GetChunk());
00124
00125 int ny_x = pl.GetChunkX() + m_loc_x;
00126 int ny_y = pl.GetChunkY() + m_loc_y;
00127 while (ny_x < 0)
00128 ny_x += area.GetWidth();
00129 while (ny_y < 0)
00130 ny_y += area.GetHeight();
00131 while (ny_x >= area.GetWidth())
00132 ny_x -= area.GetWidth();
00133 while (ny_y >= area.GetHeight())
00134 ny_y -= area.GetHeight();
00135 if (line.size() && (line[0] == 'y' || line[0] == 'Y'))
00136 {
00137 Chunk north(db, area, chunk.GetX() + ch_x, chunk.GetY() + ch_y, chunk.GetZ() + ch_z);
00138 if (!north.Exists())
00139 {
00140 north.Init(from, chunk.GetX() + ch_x, chunk.GetY() + ch_y, chunk.GetZ() + ch_z, ' ');
00141 north.Save();
00142 }
00143 if (ch_z == 1)
00144 {
00145 chunk.Set(ny_x, ny_y, 'U');
00146 north.Set(ny_x, ny_y, 'D');
00147 chunk.Save();
00148 north.Save();
00149 }
00150 else
00151 if (ch_z == -1)
00152 {
00153 chunk.Set(ny_x, ny_y, 'D');
00154 north.Set(ny_x, ny_y, 'U');
00155 chunk.Save();
00156 north.Save();
00157 }
00158 pl.SetChunk(north.GetNum());
00159 pl.SetChunkX(ny_x);
00160 pl.SetChunkY(ny_y);
00161 Look::LookMap(from);
00162 Look::Show(from);
00163 }
00164 from -> SetPrompt();
00165 }
00166
00167