Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[added] Explosive component #2261

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Entities/Characters/Builder/CommonBuilderBlocks.as
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,12 @@ void addCommonBuilderBlocks(BuildBlock[][]@ blocks, int team_num = 0, const stri
AddRequirement(b.reqs, "blob", "mat_stone", "Stone", 40);
blocks[3].push_back(b);
}
{
BuildBlock b(0, "explosive", "$explosive$", "Explosive");
AddRequirement(b.reqs, "blob", "mat_wood", "Wood", 30);
AddRequirement(b.reqs, "blob", "mat_stone", "Stone", 30);
blocks[3].push_back(b);
}
}
}

Expand Down
101 changes: 101 additions & 0 deletions Entities/Structures/Components/Load/Explosive/Explosive.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// Explosive.as

#include "MechanismsCommon.as";
#include "BombCommon.as";
#include "FireCommon.as";

const u8 FUSE_TIME = 4;

class Explosive: Component
{
u16 id;

Explosive(Vec2f position, u16 netID)
{
x = position.x;
y = position.y;

id = netID;
}

void Activate(CBlob@ this)
{
SetToExplode(this);
}

void Deactivate(CBlob@ this)
{
}
}

void onInit(CBlob@ this)
{
// used by BlobPlacement.as
this.Tag("place norotate");

// used by BuilderHittable.as
this.Tag("builder always hit");

// used by KnightLogic.as
this.Tag("blocks sword");

// used by TileBackground.as
this.set_TileType("background tile", CMap::tile_wood_back);

this.server_setTeamNum(-1);
}

void onSetStatic(CBlob@ this, const bool isStatic)
{
if (!isStatic || this.exists("component")) return;

const Vec2f position = this.getPosition() / 8;

Explosive component(position, this.getNetworkID());
this.set("component", component);

if (isServer())
{
MapPowerGrid@ grid;
if (!getRules().get("power grid", @grid)) return;

grid.setAll(
component.x, // x
component.y, // y
TOPO_CARDINAL, // input topology
TOPO_NONE, // output topology
INFO_LOAD, // information
0, // power
component.id); // id
}

CSprite@ sprite = this.getSprite();
if (sprite is null) return;

sprite.SetZ(500);
sprite.SetFacingLeft(false);
}

f32 onHit(CBlob@ this, Vec2f worldPoint, Vec2f velocity, f32 damage, CBlob@ hitterBlob, u8 customData)
{
if (isExplosionHitter(customData) || isIgniteHitter(customData))
{
SetToExplode(this);
return 0.0f;
}
return damage;
}

void SetToExplode(CBlob@ this)
{
if (!this.hasTag("exploding"))
{
CSprite@ sprite = this.getSprite();
if (sprite !is null)
{
sprite.animation.frame = 1;
}

SetupBomb(this, FUSE_TIME, 48.0f, 3.0f, 24.0f, 0.4f, true);
}
}
76 changes: 76 additions & 0 deletions Entities/Structures/Components/Load/Explosive/Explosive.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Explosive.cfg

$sprite_factory = generic_sprite
@$sprite_scripts = Wooden.as;
$sprite_texture = Explosive.png
s32_sprite_frame_width = 8
s32_sprite_frame_height = 8
f32 sprite_offset_x = 0
f32 sprite_offset_y = 0

$sprite_gibs_start = *start*
$gib_type = predefined
$gib_style = stone
u8 gib_count = 5
@u8 gib_frame = 4; 5; 6; 7;
f32 velocity = 10.0
f32 offset_x = 0.0
f32 offset_y = 0.0
$sprite_gibs_end = *end*

$sprite_animation_start = *start*
$sprite_animation_default_name = default
u16 sprite_animation_default_time = 0
u8_sprite_animation_default_loop = 0
@u16 sprite_animation_default_frames = 0; 1;
$sprite_animation_end = *end*

$shape_factory = box2d_shape
@$shape_scripts =
f32 shape_mass = 250.0
f32 shape_radius = 0.0
f32 shape_friction = 0.3
f32 shape_elasticity = 0.0
f32 shape_buoyancy = 0.8
f32 shape_drag = 0.2
bool shape_collides = yes
bool shape_ladder = no
bool shape_platform = no
@f32 verticesXY = 0.0; 0.0;
8.0; 0.0;
8.0; 8.0;
0.0; 8.0;
u8 block_support = 10
bool block_background = no
bool block_lightpasses = yes
bool block_snaptogrid = yes

$movement_factory =

$brain_factory =

$attachment_factory = generic_attachment
@$attachment_scripts =
@$attachment_points = PICKUP; 0; 0; 1; 0; 0;

$inventory_factory =

$name = explosive
@$scripts = Explosive.as;
GenericComponent.as;
isFlammable.as;
WoodStructureHit.as;
Wooden.as;
GenericHit.as;
FallOnNoSupport.as;
TileBackground.as;
GenericOnStatic.as;
f32_health = 3.5
$inventory_name = Explosive
$inventory_icon = -
u8 inventory_icon_frame = 1
u8 inventory_icon_frame_width = 8
u8 inventory_icon_frame_height = 8
u8 inventory_used_width = 0
u8 inventory_used_height = 0
u8 inventory_max_stacks = 0
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions Scripts/Default/DefaultGUI.as
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ void LoadDefaultGUI()
AddIconToken("$lamp$", "Lamp.png", Vec2f(16, 16), 3);
AddIconToken("$obstructor$", "Obstructor.png", Vec2f(8, 8), 0);
AddIconToken("$spiker$", "Spiker.png", Vec2f(16, 16), 3);
AddIconToken("$explosive$", "Explosive.png", Vec2f(8, 8), 1);

// techs
AddIconToken("$tech_stone$", "GUI/TechnologyIcons.png", Vec2f(16, 16), 16);
Expand Down
6 changes: 6 additions & 0 deletions Scripts/MapLoaders/BasePNGLoader.as
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ class PNGLoader
case map_colors::alpha_lamp: autotile(offset); spawnBlob(map, "lamp", 255, position, true); break;
case map_colors::alpha_obstructor: autotile(offset); spawnBlob(map, "obstructor", 255, position, true); break;
case map_colors::alpha_spiker: autotile(offset); spawnBlob(map, "spiker", 255, position, getAngleFromChannel(alpha), true); break;
case map_colors::alpha_explosive: autotile(offset); spawnBlob(map, "explosive", 255, position, getAngleFromChannel(alpha), true); break;
case map_colors::alpha_lever:
{
autotile(offset);
Expand Down Expand Up @@ -953,6 +954,11 @@ void getInfoFromBlob(CBlob@ this, SColor &out color, Vec2f &out offset)
color = map_colors::alpha_spiker;
color.setAlpha(getChannelFromAngle(this.getAngleDegrees()));
}
else if(name == "explosive")
{
color = map_colors::alpha_flamer;
color.setAlpha(getChannelFromAngle(this.getAngleDegrees()));
}
}

// FLORA
Expand Down
1 change: 1 addition & 0 deletions Scripts/MapLoaders/LoaderColors.as
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ namespace map_colors
alpha_lamp = 0xFFFFFF20, // ARGB(255, 255, 255, 32);
alpha_obstructor = 0xFFFFFF30, // ARGB(255, 255, 255, 48);
alpha_spiker = 0xFFFFFF40, // ARGB(255, 255, 255, 64);
alpha_explosive = 0xFFFFFF50, // ARGB(255, 255, 255, 80);

// BLOCKS
ladder = 0xFF42240B, // ARGB(255, 66, 36, 11);
Expand Down