add delayed repeater, make gates propagate light

This commit is contained in:
darkrose 2014-08-23 23:02:58 +10:00
parent 6fdc36cbea
commit 24dd10506d
6 changed files with 147 additions and 2 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 583 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 681 B

View File

@ -553,6 +553,7 @@ MapNode mapnode_translate_to_internal(MapNode n_from, u8 version);
#define CONTENT_CIRCUIT_BUTTON 0xF25 #define CONTENT_CIRCUIT_BUTTON 0xF25
#define CONTENT_CIRCUIT_PRESSUREPLATE_WOOD 0xF26 #define CONTENT_CIRCUIT_PRESSUREPLATE_WOOD 0xF26
#define CONTENT_CIRCUIT_PRESSUREPLATE_STONE 0xF27 #define CONTENT_CIRCUIT_PRESSUREPLATE_STONE 0xF27
#define CONTENT_CIRCUIT_REPEATER 0xF28
// circuits - gadgets // circuits - gadgets
#define CONTENT_CIRCUIT_LAMP 0xF40 #define CONTENT_CIRCUIT_LAMP 0xF40
#define CONTENT_CIRCUIT_LAMP_OFF 0xF41 #define CONTENT_CIRCUIT_LAMP_OFF 0xF41

View File

@ -293,9 +293,9 @@ void content_mapnode_circuit(bool repeat)
f->setAllTextures("circuit_gate.png"); f->setAllTextures("circuit_gate.png");
f->setTexture(0,"circuit_gate_top.png"); f->setTexture(0,"circuit_gate_top.png");
f->rotate_tile_with_nodebox = true; f->rotate_tile_with_nodebox = true;
f->param_type = CPT_FACEDIR_SIMPLE; f->param_type = CPT_LIGHT;
f->param2_type = CPT_FACEDIR_SIMPLE;
f->draw_type = CDT_NODEBOX; f->draw_type = CDT_NODEBOX;
f->is_ground_content = true;
f->energy_type = CET_GATE; f->energy_type = CET_GATE;
f->energy_drop = 0; f->energy_drop = 0;
f->solidness = 0; // drawn separately, makes no faces f->solidness = 0; // drawn separately, makes no faces
@ -317,6 +317,36 @@ void content_mapnode_circuit(bool repeat)
lists::add("craftguide",i); lists::add("craftguide",i);
lists::add("creative",i); lists::add("creative",i);
i = CONTENT_CIRCUIT_REPEATER;
f = &content_features(i);
f->description = std::string("Repeater");
f->setAllTextures("circuit_repeater.png");
f->setTexture(0,"circuit_repeater_top.png");
f->rotate_tile_with_nodebox = true;
f->param_type = CPT_LIGHT;
f->param2_type = CPT_FACEDIR_SIMPLE;
f->draw_type = CDT_NODEBOX;
f->energy_type = CET_GATE;
f->energy_drop = 0;
f->solidness = 0; // drawn separately, makes no faces
f->dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
f->type = CMT_STONE;
f->hardness = 1.0;
content_nodebox_logicgate(f);
f->setInventoryTextureNodeBox(i,"circuit_repeater_top.png","circuit_repeater.png","circuit_repeater.png");
if (f->initial_metadata == NULL)
f->initial_metadata = new RepeaterNodeMetadata();
{
u16 recipe[9] = {
CONTENT_IGNORE, CONTENT_IGNORE, CONTENT_IGNORE,
CONTENT_CRAFTITEM_MESEDUST, CONTENT_STONE, CONTENT_CRAFTITEM_MESEDUST,
CONTENT_IGNORE, CONTENT_IGNORE, CONTENT_IGNORE
};
crafting::setRecipe(recipe,CONTENT_CIRCUIT_REPEATER,1);
}
lists::add("craftguide",i);
lists::add("creative",i);
i = CONTENT_CIRCUIT_LAMP; i = CONTENT_CIRCUIT_LAMP;
f = &content_features(i); f = &content_features(i);
f->description = std::string("Electric Lamp"); f->description = std::string("Electric Lamp");

View File

@ -2597,6 +2597,106 @@ bool NotGateNodeMetadata::energise(u8 level, v3s16 powersrc, v3s16 signalsrc, v3
return true; return true;
} }
/*
RepeaterNodeMetadata
*/
// Prototype
RepeaterNodeMetadata proto_RepeaterNodeMetadata;
RepeaterNodeMetadata::RepeaterNodeMetadata():
m_ticks(0)
{
m_energy = 0;
m_ptime = 0;
m_sources.clear();
NodeMetadata::registerType(typeId(), create);
}
u16 RepeaterNodeMetadata::typeId() const
{
return CONTENT_CIRCUIT_REPEATER;
}
NodeMetadata* RepeaterNodeMetadata::create(std::istream &is)
{
RepeaterNodeMetadata *d = new RepeaterNodeMetadata();
int temp;
is>>temp;
d->m_energy = temp;
is>>temp;
d->m_ticks = temp;
is>>temp;
d->m_ptime = (float)temp/10;
int i;
is>>i;
v3s16 p;
for (; i > 0; i--) {
is>>temp;
p.X = temp;
is>>temp;
p.Y = temp;
is>>temp;
p.Z = temp;
is>>temp;
d->m_sources[p] = temp;
}
return d;
}
NodeMetadata* RepeaterNodeMetadata::clone()
{
RepeaterNodeMetadata *d = new RepeaterNodeMetadata();
return d;
}
void RepeaterNodeMetadata::serializeBody(std::ostream &os)
{
os<<itos(m_energy) << " ";
os<<itos(m_ticks) << " ";
os<<itos(m_ptime*10)<<" ";
os<<itos(m_sources.size()) << " ";
for (std::map<v3s16,u8>::iterator i = m_sources.begin(); i != m_sources.end(); i++) {
os<<itos(i->first.X) << " ";
os<<itos(i->first.Y) << " ";
os<<itos(i->first.Z) << " ";
os<<itos(i->second) << " ";
}
}
bool RepeaterNodeMetadata::step(float dtime, v3s16 pos, ServerEnvironment *env)
{
m_ptime += dtime;
if (m_ptime > 1.0 && m_ticks > 0) {
m_energy = 0;
m_ticks--;
}
if (!m_energy && !m_ticks) {
return false;
}else if (m_energy && m_ticks < 3) {
m_ticks++;
return true;
}
env->propogateEnergy(ENERGY_MAX,pos,pos,pos);
return true;
}
bool RepeaterNodeMetadata::energise(u8 level, v3s16 powersrc, v3s16 signalsrc, v3s16 pos)
{
if (powersrc == pos)
return true;
m_ptime = 0;
if (level && m_sources[powersrc] > level)
return false;
if (!level || m_energy < level) {
m_energy = level;
if (!level) {
m_sources.erase(powersrc);
for (std::map<v3s16,u8>::iterator i = m_sources.begin(); i != m_sources.end(); i++) {
u8 v = i->second;
if (v > m_energy)
m_energy = v;
}
}
}
return true;
}
/* /*
DoorNodeMetadata DoorNodeMetadata

View File

@ -532,6 +532,20 @@ public:
virtual bool energise(u8 level, v3s16 powersrc, v3s16 signalsrc, v3s16 pos); virtual bool energise(u8 level, v3s16 powersrc, v3s16 signalsrc, v3s16 pos);
}; };
class RepeaterNodeMetadata : public CircuitNodeMetadata
{
public:
RepeaterNodeMetadata();
virtual u16 typeId() const;
static NodeMetadata* create(std::istream &is);
virtual NodeMetadata* clone();
virtual void serializeBody(std::ostream &os);
virtual bool step(float dtime, v3s16 pos, ServerEnvironment *env);
virtual bool energise(u8 level, v3s16 powersrc, v3s16 signalsrc, v3s16 pos);
private:
u8 m_ticks;
};
class NotGateNodeMetadata : public CircuitNodeMetadata class NotGateNodeMetadata : public CircuitNodeMetadata
{ {
public: public: