freg  0.3
Free-Roaming Elementary Game
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
RainMachine.cpp
Go to the documentation of this file.
1  /* freg, Free-Roaming Elementary Game with open and interactive world
2  * Copyright (C) 2012-2014 Alexander 'mmaulwurff' Kromm
3  * mmaulwurff@gmail.com
4  *
5  * This file is part of FREG.
6  *
7  * FREG is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * FREG is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with FREG. If not, see <http://www.gnu.org/licenses/>. */
19 
20 #include "blocks/RainMachine.h"
21 
22 RainMachine::RainMachine(const int kind, const int sub) :
23  Active(kind, sub),
24  Inventory(1),
25  isOn(false)
26 {}
27 
28 RainMachine::RainMachine(QDataStream & stream, const int kind, const int sub) :
29  Active(stream, kind, sub),
30  Inventory(stream, 1),
31  isOn()
32 {
33  stream >> isOn;
34 }
35 
36 void RainMachine::SaveAttributes(QDataStream & stream) const {
37  Active::SaveAttributes(stream);
39  stream << isOn;
40 }
41 
43  if ( not isOn ) return;
44  if ( AIR == GetInvSub(0) ) {
45  if ( qrand() % 5 ) {
47  }
48  } else if ( qrand() % (20 - Number(0)*2) ) {
49  GetShred()->Rain(LIQUID, GetInvSub(0));
50  }
51 }
52 
53 QString RainMachine::FullName() const {
54  return tr("Rain Machine") + ( isOn ?
55  tr(": on") : tr(": off") );
56 }
57 
58 int RainMachine::ShouldAct() const { return FREQUENT_RARE; }
62 
63 void RainMachine::Damage(const int dmg, const int dmg_kind) {
64  if ( dmg_kind >= DAMAGE_PUSH_UP ) {
65  GetShred()->SetWeather( (isOn = not isOn) ?
67  } else {
68  Block::Damage(dmg, dmg_kind);
69  }
70 }
71 
virtual void SaveAttributes(QDataStream &) const
Definition: Block.cpp:307
usage_types Use(Block *who) override
Definition: RainMachine.cpp:60
29
Definition: header.h:189
int Number(int i) const
Definition: Inventory.cpp:28
inner_actions ActInner()
Definition: RainMachine.cpp:72
virtual void Damage(int dmg, int dmg_kind)
Definition: Block.cpp:117
RainMachine(int sub, int id)
Definition: RainMachine.cpp:22
void SetWeather(weathers)
Definition: Weather.cpp:23
int GetInvSub(int i) const
Returns AIR if slot number i is empty.
Definition: Inventory.cpp:159
int ShouldAct() const override
Definition: RainMachine.cpp:58
QString FullName() const override
Definition: RainMachine.cpp:53
Shred * GetShred() const
Definition: Active.cpp:139
inner_actions
See Shred::PhysEventsRare() for details.
Definition: Active.h:36
void ReceiveSignal(QString) override
Receive text signal.
Definition: Active.cpp:156
void ReceiveSignal(QString) override
Receive text signal.
Definition: RainMachine.cpp:59
void SaveAttributes(QDataStream &) const override
Definition: RainMachine.cpp:36
void DoRareAction() override
Definition: RainMachine.cpp:42
19
Definition: header.h:179
void Rain(int kind, int sub)
Definition: Shred.cpp:617
Definition: Active.h:46
usage_types
Definition: header.h:196
Provides block ability to contain other blocks inside.
Definition: Inventory.h:33
5
Definition: header.h:120
Inventory * HasInventory() override
Definition: RainMachine.cpp:61
Block without special physics and attributes.
Definition: Block.h:89
void Damage(int dmg, int dmg_kind) override
Definition: RainMachine.cpp:63
virtual void SaveAttributes(QDataStream &out) const
Definition: Inventory.cpp:65