21 #include <QMutexLocker>
54 default: Q_UNREACHABLE();
break;
73 const long longi,
const long lati)
83 return tr(
"Time is %1:%2.").
89 const int x_to,
const int y_to,
const int z_to,
90 const int src,
const int dest,
const int num)
93 if ( not
Build(block_to, x_to, y_to, z_to) ) {
100 const int x_from,
const int y_from,
const int z_from,
101 const int src,
const int dest,
const int num)
106 if ( inv_from->
Access() ) {
107 return Exchange(block_from, block_to, src, dest, num);
109 }
else if (
Exchange(block_from, block_to, src, dest, num) ) {
118 static const int max_xy =
GetBound();
119 return ( (0 <= x && x <= max_xy) && (0 <= y && y <= max_xy) );
139 if ( noteId >
notes.size() ) {
142 notes[noteId - 1] = note;
150 const int new_x,
const int new_y,
const int new_z)
168 case DOWN:
return dir;
181 case DOWN:
return dir;
293 connect(&timer, SIGNAL(timeout()), SLOT(
PhysEvents()));
302 for (
int i=start; i<end; ++i)
303 for (
int j=start; j<end; ++j) {
309 for (
int i=start; i<end; ++i)
310 for (
int j=start; j<end; ++j) {
327 int x_from,
int y_from,
int z_from,
331 unsigned max =
Abs(
Abs(x-=x_from) >
Abs(y-=y_from) ? x : y);
332 if (
Abs(z-=z_from) > max) {
338 for (
int i=max-1; i-- > 0; ) {
340 static_cast<unsigned>(x_from+=x)/max,
341 static_cast<unsigned>(y_from+=y)/max,
342 static_cast<unsigned>(z_from+=z)/max )->Transparent()
344 static_cast<unsigned>(x_from+max-1)/max,
345 static_cast<unsigned>(y_from+max-1)/max,
346 static_cast<unsigned>(z_from+max-1)/max )->Transparent()) )
355 const int x_from,
const int y_from,
const int z_from,
356 const int x_to,
const int y_to,
const int z_to)
360 || (x_to != x_from &&
361 GetBlock(x_to+(temp=(x_to>x_from) ? (-1) : 1), y_to, z_to)->
364 || (y_to != y_from &&
365 GetBlock(x_to, y_to+(temp=(y_to>y_from) ? (-1) : 1), z_to)->
368 || (z_to != z_from &&
369 GetBlock(x_to, y_to, z_to+(temp=(z_to>z_from) ? (-1) : 1))->
376 int newx, newy, newz;
377 if (
Focus(x, y, z, &newx, &newy, &newz, dir) ) {
378 switch (
CanMove(x, y, z, newx, newy, newz, dir) ) {
392 const int newx,
const int newy,
const int newz,
const dirs dir)
399 && falling !=
nullptr
412 block_to =
GetBlock(newx, newy, newz);
415 if ( *block != *block_to ) {
423 &&
Move(newx, newy, newz, dir) ) ?
450 const int newx,
const int newy,
const int newz,
const dirs dir)
459 Block *
const block_to = shred_to ->
GetBlock(newx_in, newy_in, newz);
461 shred_from->
PutBlock(block_to, x_in, y_in, z);
462 shred_to ->
PutBlock(block, newx_in, newy_in, newz);
470 emit
Updated(newx, newy, newz);
476 if ( block_to->
Sub() !=
AIR ) {
487 Move(x, y, z+1, dir);
492 int * x_to,
int * y_to,
int * z_to,
const dirs dir)
498 case UP: ++*z_to;
break;
499 case DOWN: --*z_to;
break;
500 case NORTH: --*y_to;
break;
501 case SOUTH: ++*y_to;
break;
502 case EAST: ++*x_to;
break;
503 case WEST: --*x_to;
break;
505 return InBounds(*x_to, *y_to, *z_to);
509 const int dmg,
const int dmg_kind)
515 const int sub = temp->
Sub();
516 if (
AIR == sub )
return 0;
521 temp->
Damage(dmg, dmg_kind);
529 Block *
const block = shred->
GetBlock(x_in_shred, y_in_shred, z);
530 bool delete_block =
true;
538 if ( delete_block ) {
542 if ( active !=
nullptr ) {
551 const int dir,
Block *
const who,
const bool anyway)
558 if ( who !=
nullptr ) {
565 const int old_transparency = target_block->
Transparent();
568 shred->
SetBlock(block, x_in, y_in, z);
569 if ( old_transparency != new_transparency ) {
594 const int src,
const int dest,
const int num)
602 if ( not inv_from ) {
604 && inv_to->Get(block_from, src) )
612 if ( src >= inv_from->Size() || inv_from->Number(src) == 0 ) {
616 inv_from->Drop(src, dest, num, inv_to);
639 const QMutexLocker locker(&
mutex);
643 emit
Notify(tr(
"Invalid active shreds number. Set to %1.").
648 emit
Notify(tr(
"Active shreds number too small, set to 3."));
651 emit
Notify(tr(
"Active shreds number too big. Set to %1.").
658 worldName(world_name),
660 settings(
home_path + worldName +
"/settings.ini", QSettings::IniFormat),
661 time(settings.value(
"time",
END_OF_NIGHT).toLongLong()),
662 timeStep(settings.value(
"time_step", 0).toInt()),
664 longitude(settings.value(
"longitude",
665 qlonglong(map.GetSpawnLongitude())).toLongLong()),
666 latitude (settings.value(
"latitude",
667 qlonglong(map.GetSpawnLatitude ())).toLongLong()),
671 evernight(settings.value(
"evernight", false).toBool()),
684 QSettings game_settings(
home_path +
"freg.ini", QSettings::IniFormat);
688 qDebug(
"%s: Invalid number of shreds. Set to %d.",
692 qDebug(
"%s: Number of shreds to small: %d. Set to %d.",
698 game_settings.setValue(
"number_of_shreds",
numShreds);
707 puts(qPrintable(tr(
"Loading world...")));
710 if ( notes_file.open(QIODevice::ReadOnly | QIODevice::Text) ) {
713 notes.append(QString(note).trimmed());
737 if ( notes_file.open(QIODevice::WriteOnly | QIODevice::Text) ) {
738 for (
int i=0; i<
notes.size(); ++i) {
739 notes_file.write(qPrintable(
notes.at(i)));
740 notes_file.putChar(
'\n');
bool Move(int x, int y, int z, dirs dir)
Check and move.
int TimeOfDay() const
This returns seconds from start of current day.
static dirs TurnRight(dirs dir)
static int CoordInShred(const int x)
Get local coordinate.
static bool InVertBounds(int z)
Shred * GetNearShred(Shred *, dirs dir) const
void DeleteBlock(Block *) const
Does not actually delete normal blocks.
int numShreds
size of loaded zone
void SetShredData(QByteArray *, long longi, long lati)
BlockManager block_manager
void GetString(QString &) const
void PhysEventsFrequent()
Shred ** FindShred(int x, int y) const
bool Drop(Block *from, int x_to, int y_to, int z_to, int src, int dest, int num)
Returns true on success.
World provides global physics and shred connection.
void ReloadAllShreds(long lati, long longi, int new_x, int new_y, int new_z)
virtual void Damage(int dmg, int dmg_kind)
virtual int DamageKind() const
void Updated(int, int, int)
Block * Normal(int sub) const
Use this to receive a pointer to normal block.
void SetBlockNoCheck(Block *, int x, int y, int z)
Puts block to coordinates xyz and activates it.
virtual int Weight() const
virtual bool Access() const
static dirs Anti(dirs dir)
bool Inscribe(int x, int y, int z)
Returns true on success. Gets a string and inscribes block.
Shred * GetShredByPos(int x, int y) const
virtual push_reaction PushResult(dirs) const
int SetNote(QString note)
void Restore()
Set maximum durability.
virtual Inventory * HasInventory()
void PutBlock(Block *const block, const int x, int y, int z)
const int MOON_LIGHT_FACTOR
void SetBlock(Block *block, int x, int y, int z)
Removes last block at xyz, then SetBlock, then makes block normal.
void Shift(int direction, long longitude, long latitude)
void AddFireLight(int x, int y, int z, int level)
QString GetNote(int note_id) const
bool Visible(int x_from, int y_from, int z_from, int x_to, int y_to, int z_to) const
At least one side of block is visible.
volatile dirs toResetDir
UP for no reset, DOWN for full reset, NSEW for side shift.
bool Exchange(Block *block_from, Block *block_to, int src, int dest, int num)
Returns true if block_from can be put into block_to.
virtual int LightRadius() const
void Jump(int x, int y, int z, dirs dir)
ulong Time() const
Returns time in seconds since world creation.
can_move_results CanMove(int x, int y, int z, int x_to, int y_to, int z_to, dirs dir)
This CAN move blocks, but not xyz block.
void Notify(QString) const
void NeedPlayer(int, int, int)
const int SUN_LIGHT_FACTOR
void ReEnlightenMove(dirs)
Called from ReloadShreds(int), enlightens only needed shreds.
Block * GetBlock(int x, int y, int z) const
virtual int DamageLevel() const
Provides declaration for class Inventory for freg.
bool Get(Block *to, int x_from, int y_from, int z_from, int src, int dest, int num)
virtual Falling * ShouldFall()
World(QString world_name, bool *error)
void NoCheckMove(int x, int y, int z, int x_to, int y_to, int z_to, dirs dir)
bool GetEvernight() const
void UpdatesEnded()
This is emitted when a pack of updates is complete.
const WorldMap * GetMap() const
virtual wearable Wearable() const
void SetShredData(QByteArray *, long longi, long lati)
QString TimeOfDayStr() const
void ReEnlighten(int x, int y, int z)
Called when block is moved.
static Block * NewBlock(int kind, int sub)
Use this to receive a pointer to new not-normal block.
times_of_day PartOfDay() const
virtual Block * DropAfterDamage(bool *delete_self)
Should return dropped block.
bool ShredInCentralZone(long longi, long lati) const
ShredStorage * shredStorage
int MiniTime() const
Returns number of physics steps since second start.
void DestroyAndReplace(int x, int y, int z)
Does not check target block durability.
void SetReloadShreds(int direction)
int numActiveShreds
size of active zone
virtual Active * ActiveBlock()
Provides block ability to contain other blocks inside.
Shred * GetShred(int i, int j) const
void DeleteAllShreds()
Also saves all shreds.
bool DirectlyVisible(int x_from, int y_from, int z_from, int x_to, int y_to, int z_to) const
bool InBounds(int x, int y) const
bool Build(Block *thing, int x, int y, int z, int dir=UP, Block *who=nullptr, bool anyway=false)
Returns true on successfull build, otherwise false.
int Damage(int x, int y, int z, int level, int dmg_kind)
Returns damaged block result durability.
Block * GetBlock(const int x, const int y, const int z) const
const int TIME_STEPS_IN_SEC
QByteArray * GetShredData(long longi, long lati) const
void Moved(int)
Emitted when world active zone moved to int direction.
int GetDurability() const
const int MAX_NOTE_LENGTH
static int CoordOfShred(const int x)
Get shred coordinate in loaded zone (from 0 to numShreds).
bool Focus(int x, int y, int z, int *x_targ, int *y_targ, int *z_targ, dirs dir) const
False on error, true if focus is received to _targ successfully.
int ShredPos(int x, int y) const
virtual void Move(dirs direction)
virtual void ReceiveSignal(QString)
Receive text signal.
int ChangeNote(QString note, int note_id)
Block without special physics and attributes.
static dirs TurnLeft(dirs dir)
virtual bool Inscribe(QString str)
Returns true on success.
QString WorldName() const
QByteArray * GetShredData(long longi, long lati) const
void SetNumActiveShreds(int num)