diff --git a/.editorconfig b/.editorconfig index 8afe0da..1eb1009 100644 --- a/.editorconfig +++ b/.editorconfig @@ -7,3 +7,6 @@ indent_style = space indent_size = 4 insert_final_newline = true trim_trailing_whitespace = true + +[*.yaml] +indent_size = 2 diff --git a/WORK.md b/WORK.md index 69427ab..a1a7049 100644 --- a/WORK.md +++ b/WORK.md @@ -4,3 +4,4 @@ * map packs (create in editor, import in game, save imported in local storage) * improve bots * save human state in classic game +* game config macro diff --git a/src/common/haxe/ru/m/tankz/bot/HardBotControl.hx b/src/common/haxe/ru/m/tankz/bot/HardBotControl.hx index 4866649..6311423 100644 --- a/src/common/haxe/ru/m/tankz/bot/HardBotControl.hx +++ b/src/common/haxe/ru/m/tankz/bot/HardBotControl.hx @@ -20,7 +20,7 @@ class HardBotControl extends BotControl { shot(); } case CELL(cell): - if (cell.layer == 2 && cell.armor > -1 && cell.armor <= tank.config.bullet.piercing) { + if (cell.layer == 2 && cell.armor > -1 && cell.armor <= tank.weapon.config.bullet.piercing) { shot(); } case EAGLE(eagle): diff --git a/src/common/haxe/ru/m/tankz/config/Config.hx b/src/common/haxe/ru/m/tankz/config/Config.hx index dbe4adf..35434eb 100644 --- a/src/common/haxe/ru/m/tankz/config/Config.hx +++ b/src/common/haxe/ru/m/tankz/config/Config.hx @@ -48,13 +48,17 @@ typedef BulletConfig = { var piercing:Int; } +typedef WeaponConfig = { + var bullet:BulletConfig; + var count:Int; +} + typedef TankConfig = { var type:TankType; var width:Float; var height:Float; var speed:Float; - var bullet:BulletConfig; - var bullets:Int; + var weapons:Array; var skin:String; @:optinal var hits:Int; @:optinal var upgrade:TankType; diff --git a/src/common/haxe/ru/m/tankz/core/Tank.hx b/src/common/haxe/ru/m/tankz/core/Tank.hx index dca0c1a..2c28058 100755 --- a/src/common/haxe/ru/m/tankz/core/Tank.hx +++ b/src/common/haxe/ru/m/tankz/core/Tank.hx @@ -17,6 +17,8 @@ class Tank extends MobileEntity { public var protect(default, default):Bool; public var freezing(default, default):Bool; + public var weapons(default, null):Array; + public var weapon(get, null):Weapon; public var info(get, null):TankInfo; public function new(id:Int, rect:Rectangle, playerId:PlayerId, config:TankConfig) { @@ -28,6 +30,10 @@ class Tank extends MobileEntity { this.layer = 1; } + private function get_weapon():Weapon { + return weapons[0]; + } + private function set_config(value:TankConfig):TankConfig { var d = rect.direction; rect = new Rectangle(rect.x, rect.y, value.width, value.height); @@ -35,6 +41,7 @@ class Tank extends MobileEntity { speed = value.speed; config = value; hits = config.hits; + weapons = config.weapons.map(function(weaponConfig) return new Weapon(weaponConfig)); return value; } diff --git a/src/common/haxe/ru/m/tankz/core/Weapon.hx b/src/common/haxe/ru/m/tankz/core/Weapon.hx new file mode 100644 index 0000000..59b7dee --- /dev/null +++ b/src/common/haxe/ru/m/tankz/core/Weapon.hx @@ -0,0 +1,12 @@ +package ru.m.tankz.core; + +import ru.m.tankz.config.Config; + +class Weapon { + + public var config(default, null):WeaponConfig; + + public function new(config:WeaponConfig) { + this.config = config; + } +} diff --git a/src/common/haxe/ru/m/tankz/game/EntityBuilder.hx b/src/common/haxe/ru/m/tankz/game/EntityBuilder.hx index f3b4966..973b18f 100644 --- a/src/common/haxe/ru/m/tankz/game/EntityBuilder.hx +++ b/src/common/haxe/ru/m/tankz/game/EntityBuilder.hx @@ -58,7 +58,7 @@ class EntityBuilder { public function buildBullet(point:Point, direction:Direction, playerId:PlayerId, type:TankType):Bullet { var tankConfig = config.getTank(type); - var bulletConfig = tankConfig.bullet; + var bulletConfig = tankConfig.weapons[0].bullet; var bullet = new Bullet(++entityId, new Rectangle(point.x - bulletConfig.width / 2, point.y - bulletConfig.height / 2, bulletConfig.width, bulletConfig.height, direction), playerId, bulletConfig); return bullet; } diff --git a/src/common/haxe/ru/m/tankz/game/GameRunner.hx b/src/common/haxe/ru/m/tankz/game/GameRunner.hx index 0c6dd8c..e819d94 100644 --- a/src/common/haxe/ru/m/tankz/game/GameRunner.hx +++ b/src/common/haxe/ru/m/tankz/game/GameRunner.hx @@ -259,7 +259,7 @@ class GameRunner extends Game implements EngineListener { case ACTION(tankId, SHOT): var tank:Tank = cast engine.entities.get(tankId); var player = getPlayer(tank.playerId); - if (!tank.freezing && player.bullets < tank.config.bullets) { + if (!tank.freezing && player.bullets < tank.weapon.config.count) { var rect = tank.rect; var point = rect.center.add(new Point(rect.width / 4 * rect.direction.x, rect.height / 4 * rect.direction.y)); var bullet = builder.buildBullet(point, rect.direction, player.id, tank.config.type); diff --git a/src/common/resources/config/classic.yaml b/src/common/resources/config/classic.yaml index 0432fab..24675ad 100644 --- a/src/common/resources/config/classic.yaml +++ b/src/common/resources/config/classic.yaml @@ -61,90 +61,83 @@ tanks: width: 36 height: 36 speed: 2.5 - bullet: - <<: *bullet - speed: 8.0 bullets: 1 skin: pa + weapons: + - bullet: {<<: *bullet, speed: 8.0} + count: 1 - type: human1 upgrade: human2 width: 40 height: 36 speed: 3.0 - bullet: - <<: *bullet - speed: 8.5 bullets: 1 skin: pb + weapons: + - bullet: {<<: *bullet, speed: 8.5} + count: 1 - type: human2 upgrade: human3 width: 40 height: 36 speed: 3.0 - bullet: - <<: *bullet - speed: 9.0 - bullets: 2 skin: pc + weapons: + - bullet: {<<: *bullet, speed: 9.0} + count: 2 - type: human3 downgrade: human2 width: 42 height: 38 speed: 2.9 - bullet: - <<: *bullet - speed: 9.0 - piercing: 3 - bullets: 2 skin: pd + weapons: + - bullet: {<<: *bullet, speed: 9.0, piercing: 3} + count: 2 - type: bot0 width: 38 height: 36 speed: 2.0 - bullet: - <<: *bullet - speed: 7.0 - bullets: 1 score: 100 skin: ba + weapons: + - bullet: {<<: *bullet, speed: 7.0} + count: 1 - type: bot1 width: 40 height: 36 speed: 4.0 - bullet: - <<: *bullet - speed: 7.0 - bullets: 1 score: 200 skin: bb + weapons: + - bullet: {<<: *bullet, speed: 7.0} + count: 1 - type: bot2 width: 38 height: 36 speed: 2.0 - bullet: - <<: *bullet - speed: 9.0 - bullets: 1 score: 300 skin: bc + weapons: + - bullet: {<<: *bullet, speed: 9.0} + count: 1 - type: bot3 width: 40 height: 36 speed: 1.8 - bullet: - <<: *bullet - speed: 8.0 - bullets: 1 score: 400 hits: 3 skin: bd + weapons: + - bullet: {<<: *bullet, speed: 8.0} + count: 1 bonuses: - {score: 500, factory: freeze.team, type: clock, duration: 10} diff --git a/src/common/resources/config/death.yaml b/src/common/resources/config/death.yaml index 5f981d6..c83c45d 100644 --- a/src/common/resources/config/death.yaml +++ b/src/common/resources/config/death.yaml @@ -81,11 +81,10 @@ tanks: width: 38 height: 36 speed: 2.3 - bullet: - <<: *bullet - speed: 12.0 - bullets: 2 score: 100 skin: pc + weapons: + - bullet: {<<: *bullet, speed: 12.0} + count: 2 bonuses: [] diff --git a/src/common/resources/config/dota.yaml b/src/common/resources/config/dota.yaml index fd6bfb6..f67ce9c 100644 --- a/src/common/resources/config/dota.yaml +++ b/src/common/resources/config/dota.yaml @@ -88,23 +88,21 @@ tanks: width: 38 height: 36 speed: 2.3 - bullet: - <<: *bullet - speed: 12.0 - bullets: 1 score: 100 skin: bc + weapons: + - bullet: {<<: *bullet, speed: 12.0} + count: 1 - type: fast width: 40 height: 36 speed: 4.0 - bullet: - <<: *bullet - speed: 8.0 - bullets: 1 score: 100 skin: bb + weapons: + - bullet: {<<: *bullet, speed: 8.0} + count: 1 bonuses: - {score: 100, factory: freeze.team, type: clock, duration: 10}