add support for multiple teleport points with coloured oerkki dust

This commit is contained in:
darkrose 2015-05-20 22:32:55 +10:00
parent 3f1f7d4899
commit d6f6fac945
15 changed files with 230 additions and 25 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 439 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 439 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 445 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 437 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 443 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 437 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 439 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 438 B

View File

@ -1,3 +1,28 @@
/************************************************************************
* Minetest-c55
* Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
*
* content_craftitem.cpp
* voxelands - 3d voxel world sandbox game
* Copyright (C) Lisa 'darkrose' Milne 2013-2015 <lisa@ltmnet.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
* License updated from GPLv2 or later to GPLv3 or later by Lisa Milne
* for Voxelands.
************************************************************************/
#include "content_craftitem.h"
#include "content_mapnode.h"
#include "content_craft.h"
@ -5,6 +30,7 @@
#include "content_list.h"
#include <map>
#include "intl.h"
#include "player.h"
std::map<content_t,struct CraftItemFeatures> g_content_craftitem_features;
@ -684,6 +710,7 @@ void content_craftitem_init()
f->name = "oerkki_dust";
f->description = wgettext("Oerkki Dust");
f->drop_count = 1;
f->teleports = PLAYERFLAG_HOME; // teleports player to default home location
lists::add("creative",i);
i = CONTENT_CRAFTITEM_FISH;
@ -1121,4 +1148,99 @@ void content_craftitem_init()
lists::add("craftguide",i);
lists::add("creative",i);
i = CONTENT_CRAFTITEM_OERKKI_DUST_WHITE;
f = &g_content_craftitem_features[i];
f->content = i;
f->texture = "oerkki_dust_white.png";
f->name = "oerkki_dust_white";
f->description = wgettext("White Oerkki Dust");
f->drop_count = 1;
f->teleports = PLAYERFLAG_WHITE;
crafting::set1Any2Recipe(CONTENT_CRAFTITEM_OERKKI_DUST,CONTENT_CRAFTITEM_DYE_WHITE,CONTENT_CRAFTITEM_OERKKI_DUST_WHITE);
lists::add("craftguide",i);
lists::add("creative",i);
i = CONTENT_CRAFTITEM_OERKKI_DUST_BLUE;
f = &g_content_craftitem_features[i];
f->content = i;
f->texture = "oerkki_dust_blue.png";
f->name = "oerkki_dust_blue";
f->description = wgettext("Blue Oerkki Dust");
f->drop_count = 1;
f->teleports = PLAYERFLAG_BLUE;
crafting::set1Any2Recipe(CONTENT_CRAFTITEM_OERKKI_DUST,CONTENT_CRAFTITEM_DYE_BLUE,CONTENT_CRAFTITEM_OERKKI_DUST_BLUE);
lists::add("craftguide",i);
lists::add("creative",i);
i = CONTENT_CRAFTITEM_OERKKI_DUST_GREEN;
f = &g_content_craftitem_features[i];
f->content = i;
f->texture = "oerkki_dust_green.png";
f->name = "oerkki_dust_green";
f->description = wgettext("Green Oerkki Dust");
f->drop_count = 1;
f->teleports = PLAYERFLAG_GREEN;
crafting::set1Any2Recipe(CONTENT_CRAFTITEM_OERKKI_DUST,CONTENT_CRAFTITEM_DYE_GREEN,CONTENT_CRAFTITEM_OERKKI_DUST_GREEN);
lists::add("craftguide",i);
lists::add("creative",i);
i = CONTENT_CRAFTITEM_OERKKI_DUST_ORANGE;
f = &g_content_craftitem_features[i];
f->content = i;
f->texture = "oerkki_dust_orange.png";
f->name = "oerkki_dust_orange";
f->description = wgettext("Orange Oerkki Dust");
f->drop_count = 1;
f->teleports = PLAYERFLAG_ORANGE;
crafting::set1Any2Recipe(CONTENT_CRAFTITEM_OERKKI_DUST,CONTENT_CRAFTITEM_DYE_ORANGE,CONTENT_CRAFTITEM_OERKKI_DUST_ORANGE);
lists::add("craftguide",i);
lists::add("creative",i);
i = CONTENT_CRAFTITEM_OERKKI_DUST_PURPLE;
f = &g_content_craftitem_features[i];
f->content = i;
f->texture = "oerkki_dust_purple.png";
f->name = "oerkki_dust_purple";
f->description = wgettext("Purple Oerkki Dust");
f->drop_count = 1;
f->teleports = PLAYERFLAG_PURPLE;
crafting::set1Any2Recipe(CONTENT_CRAFTITEM_OERKKI_DUST,CONTENT_CRAFTITEM_DYE_PURPLE,CONTENT_CRAFTITEM_OERKKI_DUST_PURPLE);
lists::add("craftguide",i);
lists::add("creative",i);
i = CONTENT_CRAFTITEM_OERKKI_DUST_RED;
f = &g_content_craftitem_features[i];
f->content = i;
f->texture = "oerkki_dust_red.png";
f->name = "oerkki_dust_red";
f->description = wgettext("Red Oerkki Dust");
f->drop_count = 1;
f->teleports = PLAYERFLAG_RED;
crafting::set1Any2Recipe(CONTENT_CRAFTITEM_OERKKI_DUST,CONTENT_CRAFTITEM_DYE_RED,CONTENT_CRAFTITEM_OERKKI_DUST_RED);
lists::add("craftguide",i);
lists::add("creative",i);
i = CONTENT_CRAFTITEM_OERKKI_DUST_YELLOW;
f = &g_content_craftitem_features[i];
f->content = i;
f->texture = "oerkki_dust_yellow.png";
f->name = "oerkki_dust_yellow";
f->description = wgettext("Yellow Oerkki Dust");
f->drop_count = 1;
f->teleports = PLAYERFLAG_YELLOW;
crafting::set1Any2Recipe(CONTENT_CRAFTITEM_OERKKI_DUST,CONTENT_CRAFTITEM_DYE_YELLOW,CONTENT_CRAFTITEM_OERKKI_DUST_YELLOW);
lists::add("craftguide",i);
lists::add("creative",i);
i = CONTENT_CRAFTITEM_OERKKI_DUST_BLACK;
f = &g_content_craftitem_features[i];
f->content = i;
f->texture = "oerkki_dust_black.png";
f->name = "oerkki_dust_black";
f->description = wgettext("Black Oerkki Dust");
f->drop_count = 1;
f->teleports = PLAYERFLAG_BLACK;
crafting::set1Any2Recipe(CONTENT_CRAFTITEM_OERKKI_DUST,CONTENT_CRAFTITEM_DYE_BLACK,CONTENT_CRAFTITEM_OERKKI_DUST_BLACK);
lists::add("craftguide",i);
lists::add("creative",i);
}

View File

@ -42,6 +42,9 @@ struct CraftItemFeatures {
s16 edible;
// the number dropped on right click, -1 for all
s16 drop_count;
// if this teleports the player home, -2 = no, -1 = default home
// 0-7 for specific flag colours
s8 teleports;
// used by mobs that are picked up
content_t drop_item;
// used by snowballs and such... things that are thrown
@ -58,6 +61,7 @@ struct CraftItemFeatures {
fuel_time(0.0),
edible(0),
drop_count(-1),
teleports(-2),
drop_item(CONTENT_IGNORE),
thrown_item(CONTENT_IGNORE),
shot_item(CONTENT_IGNORE)
@ -171,5 +175,13 @@ CraftItemFeatures & content_craftitem_features(std::string subname);
#define CONTENT_CRAFTITEM_LEATHER_BLACK (CONTENT_CRAFTITEM_MASK | 0x6A)
#define CONTENT_CRAFTITEM_ARROW (CONTENT_CRAFTITEM_MASK | 0x6B)
#define CONTENT_CRAFTITEM_FERTILIZER (CONTENT_CRAFTITEM_MASK | 0x6C)
#define CONTENT_CRAFTITEM_OERKKI_DUST_WHITE (CONTENT_CRAFTITEM_MASK | 0x6D)
#define CONTENT_CRAFTITEM_OERKKI_DUST_BLUE (CONTENT_CRAFTITEM_MASK | 0x6E)
#define CONTENT_CRAFTITEM_OERKKI_DUST_GREEN (CONTENT_CRAFTITEM_MASK | 0x6F)
#define CONTENT_CRAFTITEM_OERKKI_DUST_ORANGE (CONTENT_CRAFTITEM_MASK | 0x70)
#define CONTENT_CRAFTITEM_OERKKI_DUST_PURPLE (CONTENT_CRAFTITEM_MASK | 0x71)
#define CONTENT_CRAFTITEM_OERKKI_DUST_RED (CONTENT_CRAFTITEM_MASK | 0x72)
#define CONTENT_CRAFTITEM_OERKKI_DUST_YELLOW (CONTENT_CRAFTITEM_MASK | 0x73)
#define CONTENT_CRAFTITEM_OERKKI_DUST_BLACK (CONTENT_CRAFTITEM_MASK | 0x74)
#endif

View File

@ -24,6 +24,7 @@
#include "content_list.h"
#include "content_craft.h"
#include "content_nodemeta.h"
#include "player.h"
#include "intl.h"
void content_mapnode_special(bool repeat)
@ -1688,7 +1689,7 @@ void content_mapnode_special(bool repeat)
f->air_equivalent = true; // grass grows underneath
content_nodebox_flag(f);
f->setInventoryTextureNodeBox(i,"flag.png","flag.png","flag_end.png");
f->home_node = true;
f->home_node = PLAYERFLAG_WHITE;
f->type = CMT_WOOD;
f->hardness = 0.4;
f->suffocation_per_second = 0;
@ -1738,7 +1739,7 @@ void content_mapnode_special(bool repeat)
f->air_equivalent = true; // grass grows underneath
content_nodebox_flag(f);
f->setInventoryTextureNodeBox(i,"flag_blue.png","flag_blue.png","flag_blue_end.png");
f->home_node = true;
f->home_node = PLAYERFLAG_BLUE;
f->type = CMT_WOOD;
f->hardness = 0.4;
f->suffocation_per_second = 0;
@ -1767,7 +1768,7 @@ void content_mapnode_special(bool repeat)
f->air_equivalent = true; // grass grows underneath
content_nodebox_flag(f);
f->setInventoryTextureNodeBox(i,"flag_green.png","flag_green.png","flag_green_end.png");
f->home_node = true;
f->home_node = PLAYERFLAG_GREEN;
f->type = CMT_WOOD;
f->hardness = 0.4;
f->suffocation_per_second = 0;
@ -1796,7 +1797,7 @@ void content_mapnode_special(bool repeat)
f->air_equivalent = true; // grass grows underneath
content_nodebox_flag(f);
f->setInventoryTextureNodeBox(i,"flag_orange.png","flag_orange.png","flag_orange_end.png");
f->home_node = true;
f->home_node = PLAYERFLAG_ORANGE;
f->type = CMT_WOOD;
f->hardness = 0.4;
f->suffocation_per_second = 0;
@ -1825,7 +1826,7 @@ void content_mapnode_special(bool repeat)
f->air_equivalent = true; // grass grows underneath
content_nodebox_flag(f);
f->setInventoryTextureNodeBox(i,"flag_purple.png","flag_purple.png","flag_purple_end.png");
f->home_node = true;
f->home_node = PLAYERFLAG_PURPLE;
f->type = CMT_WOOD;
f->hardness = 0.4;
f->suffocation_per_second = 0;
@ -1854,7 +1855,7 @@ void content_mapnode_special(bool repeat)
f->air_equivalent = true; // grass grows underneath
content_nodebox_flag(f);
f->setInventoryTextureNodeBox(i,"flag_red.png","flag_red.png","flag_red_end.png");
f->home_node = true;
f->home_node = PLAYERFLAG_RED;
f->type = CMT_WOOD;
f->hardness = 0.4;
f->suffocation_per_second = 0;
@ -1883,7 +1884,7 @@ void content_mapnode_special(bool repeat)
f->air_equivalent = true; // grass grows underneath
content_nodebox_flag(f);
f->setInventoryTextureNodeBox(i,"flag_yellow.png","flag_yellow.png","flag_yellow_end.png");
f->home_node = true;
f->home_node = PLAYERFLAG_YELLOW;
f->type = CMT_WOOD;
f->hardness = 0.4;
f->suffocation_per_second = 0;
@ -1912,7 +1913,7 @@ void content_mapnode_special(bool repeat)
f->air_equivalent = true; // grass grows underneath
content_nodebox_flag(f);
f->setInventoryTextureNodeBox(i,"flag_black.png","flag_black.png","flag_black_end.png");
f->home_node = true;
f->home_node = PLAYERFLAG_BLACK;
f->type = CMT_WOOD;
f->hardness = 0.4;
f->suffocation_per_second = 0;

View File

@ -435,7 +435,7 @@ struct ContentFeatures
u32 pressure_per_second;
// can be used to set the users respawn position
bool home_node;
s8 home_node;
// NOTE: Move relevant properties to here from elsewhere
@ -514,7 +514,7 @@ struct ContentFeatures
suffocation_per_second = 4;
warmth_per_second = 0;
pressure_per_second = 0;
home_node = false;
home_node = -1;
}
ContentFeatures()

View File

@ -64,6 +64,9 @@ Player::Player():
m_given_clothes(false)
{
updateName("<not set>");
for (u8 i=0; i<PLAYERFLAG_COUNT; i++) {
m_hasflag[i] = false;
}
resetInventory();
}
@ -196,6 +199,14 @@ void Player::serialize(std::ostream &os)
args.setS32("hunger", hunger);
if (m_hashome)
args.setV3F("home",m_home);
const char* flags[8] = {"white","blue","green","orange","purple","red","yellow","black"};
for (u16 i=0; i<8; i++) {
std::string n("flag_");
n += flags[i];
if (!m_hasflag[i])
continue;
args.setV3F(n,m_flag[i]);
}
if (m_given_clothes)
args.set("clothes_given","true");
@ -253,6 +264,19 @@ void Player::deSerialize(std::istream &is)
}else{
m_hashome = false;
}
const char* flags[8] = {"white","blue","green","orange","purple","red","yellow","black"};
for (u16 i=0; i<8; i++) {
std::string n("flag_");
n += flags[i];
m_hasflag[i] = args.exists(n);
if (!m_hasflag[i])
continue;
m_flag[i] = args.getV3F(n);
if (!m_hashome) {
m_home = m_flag[i];
m_hashome = true;
}
}
if (args.exists("clothes_given")) {
m_given_clothes = args.getBool("clothes_given");
}else{
@ -263,20 +287,53 @@ void Player::deSerialize(std::istream &is)
checkInventory();
}
bool Player::getHome(v3f &h)
bool Player::getHome(s8 i, v3f &h)
{
if (!m_hashome)
return false;
h = m_home;
if (i == PLAYERFLAG_HOME) {
if (!m_hashome)
return false;
h = m_home;
}else if (i > PLAYERFLAG_HOME && i < PLAYERFLAG_COUNT) {
if (!m_hasflag[i])
return false;
h = m_flag[i];
}
return true;
}
void Player::setHome(v3f h)
void Player::setHome(s8 i, v3f h)
{
if (i > PLAYERFLAG_HOME && i < PLAYERFLAG_COUNT) {
m_flag[i] = h;
m_hasflag[i] = true;
}
m_home = h;
m_hashome = true;
}
void Player::unsetHome(s8 i)
{
bool reset = false;
if (i == PLAYERFLAG_HOME) {
reset = true;
}else if (i > PLAYERFLAG_HOME && i < PLAYERFLAG_COUNT) {
if (m_hashome && m_hasflag[i] && m_home == m_flag[i])
reset = true;
m_hasflag[i] = false;
}
if (!reset)
return;
m_hashome = false;
for (u8 i=0; i<PLAYERFLAG_COUNT; i++) {
if (!m_hasflag[i])
continue;
m_hashome = true;
m_home = m_flag[i];
}
}
v3f Player::getScale()
{
if (m_character == "")

View File

@ -44,6 +44,17 @@
#define PLAYERANIM_WALKDIG 3
#define PLAYERANIM_DIE 4
#define PLAYERFLAG_HOME -1
#define PLAYERFLAG_WHITE 0
#define PLAYERFLAG_BLUE 1
#define PLAYERFLAG_GREEN 2
#define PLAYERFLAG_ORANGE 3
#define PLAYERFLAG_PURPLE 4
#define PLAYERFLAG_RED 5
#define PLAYERFLAG_YELLOW 6
#define PLAYERFLAG_BLACK 7
#define PLAYERFLAG_COUNT 8
class Map;
class Player
@ -181,9 +192,9 @@ public:
u16 peer_id;
bool getHome(v3f &h);
void setHome(v3f h);
void unsetHome() {m_hashome = false;}
bool getHome(s8 i, v3f &h);
void setHome(s8 i, v3f h);
void unsetHome(s8 i);
f32 getArmourProtection()
{
@ -267,6 +278,8 @@ protected:
v3f m_position;
v3f m_home;
bool m_hashome;
v3f m_flag[PLAYERFLAG_COUNT];
bool m_hasflag[PLAYERFLAG_COUNT];
std::string m_character;
bool m_given_clothes;

View File

@ -3347,8 +3347,8 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
}
sendRemoveNode(p_under, 0, &far_players, 30);
}else{
if (content_features(n).home_node)
player->unsetHome();
if (content_features(n).home_node > -1)
player->unsetHome(content_features(n).home_node);
if (n.getContent() == CONTENT_FLOWER_POT) {
MapNode a = m_env.getMap().getNodeNoEx(p_under+v3s16(0,1,0));
if (
@ -4104,10 +4104,10 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
}
}
if (content_features(n).home_node) {
if (content_features(n).home_node > -1) {
v3f player_home = intToFloat(p_under,BS);
player_home.Y += 0.6*BS;
player->setHome(player_home);
player->setHome(content_features(n).home_node,player_home);
std::string msg = std::string("Server: -!- Your home is now set to ")+itos(p_under.X)+","+itos(p_under.Y+1)+","+itos(p_under.Z);
SendChatMessage(player->peer_id,narrow_to_wide(msg).c_str());
}
@ -4372,7 +4372,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
continue;
client->SetBlocksNotSent(modified_blocks);
}
}else if (item->getContent() == CONTENT_CRAFTITEM_OERKKI_DUST) {
}else if (content_craftitem_features(item->getContent()).teleports > -2) {
/*
If in creative mode, item dropping is disabled unless
player has build privileges
@ -4406,7 +4406,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
SendInventory(peer_id);
}
v3f pos;
if (!player->getHome(pos))
if (!player->getHome(content_craftitem_features(item->getContent()).teleports,pos) && !player->getHome(PLAYERFLAG_HOME,pos))
pos = findSpawnPos(m_env.getServerMap());
player->setPosition(pos);
SendMovePlayer(player);
@ -5925,7 +5925,7 @@ void Server::HandlePlayerHP(Player *player, s16 damage, s16 suffocate, s16 hunge
void Server::RespawnPlayer(Player *player)
{
v3f pos;
if (!player->getHome(pos))
if (!player->getHome(PLAYERFLAG_HOME,pos))
pos = findSpawnPos(m_env.getServerMap());
player->setPosition(pos);
player->hp = 20;