# HG changeset patch # User Wuzzy # Date 1558560742 -7200 # Node ID 8cde6fb2fabdb3cb7a80d5f9b1e526167d45e25e # Parent 2e89487540d817425bc1448481df29744e40df5f# Parent 88e3d1ff67bbc4bb58bb359dc76ba80427c62cb7 Merge alfadur's commits diff -r 2e89487540d8 -r 8cde6fb2fabd hedgewars/uConsts.pas --- a/hedgewars/uConsts.pas Wed May 22 23:30:10 2019 +0200 +++ b/hedgewars/uConsts.pas Wed May 22 23:32:22 2019 +0200 @@ -155,6 +155,7 @@ MAXNAMELEN = 192; MAXROPEPOINTS = 3840; + MAXROPELAYERS = 16; {$IFNDEF PAS2C} // some opengl headers do not have these macros diff -r 2e89487540d8 -r 8cde6fb2fabd hedgewars/uGearsRender.pas --- a/hedgewars/uGearsRender.pas Wed May 22 23:30:10 2019 +0200 +++ b/hedgewars/uGearsRender.pas Wed May 22 23:32:22 2019 +0200 @@ -95,7 +95,7 @@ end; -function DrawRopeLine(X1, Y1, X2, Y2, roplen: LongInt): LongInt; +function DrawRopeLine(X1, Y1, X2, Y2, roplen: LongInt; LayerIndex: Longword): LongInt; var eX, eY, dX, dY: LongInt; i, sX, sY, x, y, d: LongInt; b: boolean; @@ -162,42 +162,46 @@ if b then begin inc(roplen); - if (roplen mod cRopeNodeStep) = 0 then + if (roplen mod (cRopeNodeStep * cRopeLayers)) = (cRopeNodeStep * LayerIndex) then DrawSpriteRotatedF(sprRopeNode, x, y, roplen div cRopeNodeStep, 1, angle); end end; DrawRopeLine:= roplen; end; +procedure DrawRopeLayer(Gear: PGear; LayerIndex: LongWord); +var roplen, i: LongInt; +begin + roplen:= 0; + if RopePoints.Count > 0 then + begin + i:= 0; + while i < Pred(RopePoints.Count) do + begin + roplen:= DrawRopeLine(hwRound(RopePoints.ar[i].X) + WorldDx, hwRound(RopePoints.ar[i].Y) + WorldDy, + hwRound(RopePoints.ar[Succ(i)].X) + WorldDx, hwRound(RopePoints.ar[Succ(i)].Y) + WorldDy, roplen, LayerIndex); + inc(i) + end; + roplen:= DrawRopeLine(hwRound(RopePoints.ar[i].X) + WorldDx, hwRound(RopePoints.ar[i].Y) + WorldDy, + hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, roplen, LayerIndex); + roplen:= DrawRopeLine(hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, + hwRound(Gear^.Hedgehog^.Gear^.X) + WorldDx, hwRound(Gear^.Hedgehog^.Gear^.Y) + WorldDy, roplen, LayerIndex); + end + else + if Gear^.Elasticity.QWordValue > 0 then + roplen:= DrawRopeLine(hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, + hwRound(Gear^.Hedgehog^.Gear^.X) + WorldDx, hwRound(Gear^.Hedgehog^.Gear^.Y) + WorldDy, roplen, LayerIndex); +end; + procedure DrawRope(Gear: PGear); -var roplen, i: LongInt; +var i: LongInt; begin if Gear^.Hedgehog^.Gear = nil then exit; if (Gear^.Tag = 1) or ((cReducedQuality and rqSimpleRope) <> 0) then DrawRopeLinesRQ(Gear) else - begin - roplen:= 0; - if RopePoints.Count > 0 then - begin - i:= 0; - while i < Pred(RopePoints.Count) do - begin - roplen:= DrawRopeLine(hwRound(RopePoints.ar[i].X) + WorldDx, hwRound(RopePoints.ar[i].Y) + WorldDy, - hwRound(RopePoints.ar[Succ(i)].X) + WorldDx, hwRound(RopePoints.ar[Succ(i)].Y) + WorldDy, roplen); - inc(i) - end; - roplen:= DrawRopeLine(hwRound(RopePoints.ar[i].X) + WorldDx, hwRound(RopePoints.ar[i].Y) + WorldDy, - hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, roplen); - roplen:= DrawRopeLine(hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, - hwRound(Gear^.Hedgehog^.Gear^.X) + WorldDx, hwRound(Gear^.Hedgehog^.Gear^.Y) + WorldDy, roplen); - end - else - if Gear^.Elasticity.QWordValue > 0 then - roplen:= DrawRopeLine(hwRound(Gear^.X) + WorldDx, hwRound(Gear^.Y) + WorldDy, - hwRound(Gear^.Hedgehog^.Gear^.X) + WorldDx, hwRound(Gear^.Hedgehog^.Gear^.Y) + WorldDy, roplen); - end; - + for i := 0 to cRopeLayers - 1 do + DrawRopeLayer(Gear, i); if RopePoints.Count > 0 then DrawSpriteRotated(sprRopeHook, hwRound(RopePoints.ar[0].X) + WorldDx, hwRound(RopePoints.ar[0].Y) + WorldDy, 1, RopePoints.HookAngle) diff -r 2e89487540d8 -r 8cde6fb2fabd hedgewars/uLandObjects.pas --- a/hedgewars/uLandObjects.pas Wed May 22 23:30:10 2019 +0200 +++ b/hedgewars/uLandObjects.pas Wed May 22 23:32:22 2019 +0200 @@ -1061,7 +1061,9 @@ else if key = 'snow' then cSnow:= true else if key = 'rope-step' then - cRopeNodeStep:= StrToInt(s) + cRopeNodeStep:= max(1, StrToInt(s)) + else if key = 'rope-layers' then + cRopeLayers:= max(1, min(MAXROPELAYERS, StrToInt(s))) else if key = 'sd-water-top' then begin i:= Pos(',', s); diff -r 2e89487540d8 -r 8cde6fb2fabd hedgewars/uVariables.pas --- a/hedgewars/uVariables.pas Wed May 22 23:30:10 2019 +0200 +++ b/hedgewars/uVariables.pas Wed May 22 23:32:22 2019 +0200 @@ -117,6 +117,7 @@ cMapGen : TMapGen; cRopePercent : LongWord; cRopeNodeStep : LongWord; + cRopeLayers : LongInt; cGetAwayTime : LongWord; cAdvancedMapGenMode: boolean; @@ -2883,6 +2884,7 @@ cDamagePercent := 100; cRopePercent := 100; cRopeNodeStep := 4; + cRopeLayers := 1; cGetAwayTime := 100; cMineDudPercent := 0; cTemplateFilter := 0; diff -r 2e89487540d8 -r 8cde6fb2fabd rust/hedgewars-server/src/server/handlers/inroom.rs --- a/rust/hedgewars-server/src/server/handlers/inroom.rs Wed May 22 23:30:10 2019 +0200 +++ b/rust/hedgewars-server/src/server/handlers/inroom.rs Wed May 22 23:32:22 2019 +0200 @@ -17,8 +17,7 @@ }; use base64::{decode, encode}; use log::*; -use std::iter::once; -use std::mem::swap; +use std::{cmp::min, iter::once, mem::swap}; #[derive(Clone)] struct ByMsg<'a> { @@ -166,7 +165,7 @@ MaxTeams(count) => { if !client.is_master() { response.add(Warning("You're not the room master!".to_string()).send_self()); - } else if count < 2 || count > MAX_TEAMS_IN_ROOM { + } else if !(2..=MAX_TEAMS_IN_ROOM).contains(&count) { response .add(Warning("/maxteams: specify number from 2 to 8".to_string()).send_self()); } else { @@ -291,12 +290,13 @@ SetHedgehogsNumber(team_name, number) => { let addable_hedgehogs = room.addable_hedgehogs(); if let Some((_, team)) = room.find_team_and_owner_mut(|t| t.name == team_name) { + let max_hedgehogs = min( + MAX_HEDGEHOGS_PER_TEAM, + addable_hedgehogs + team.hedgehogs_number, + ); if !client.is_master() { response.add(Error("You're not the room master!".to_string()).send_self()); - } else if number < 1 - || number > MAX_HEDGEHOGS_PER_TEAM - || number > addable_hedgehogs + team.hedgehogs_number - { + } else if !(1..=max_hedgehogs).contains(&number) { response .add(HedgehogsNumber(team.name.clone(), team.hedgehogs_number).send_self()); } else { diff -r 2e89487540d8 -r 8cde6fb2fabd rust/hedgewars-server/src/utils.rs --- a/rust/hedgewars-server/src/utils.rs Wed May 22 23:30:10 2019 +0200 +++ b/rust/hedgewars-server/src/utils.rs Wed May 22 23:32:22 2019 +0200 @@ -14,7 +14,7 @@ || name.trim() != name || name .chars() - .any(|c| "$()*+?[]^{|}\x7F".contains(c) || '\x00' <= c && c <= '\x1F') + .any(|c| "$()*+?[]^{|}\x7F".contains(c) || ('\x00'..='\x1F').contains(&c)) } pub fn to_engine_msg(msg: T) -> String diff -r 2e89487540d8 -r 8cde6fb2fabd rust/integral-geometry/src/lib.rs --- a/rust/integral-geometry/src/lib.rs Wed May 22 23:30:10 2019 +0200 +++ b/rust/integral-geometry/src/lib.rs Wed May 22 23:32:22 2019 +0200 @@ -1,7 +1,7 @@ use fpnum::{distance, fp, FPNum, FPPoint}; use std::{ cmp::{max, min}, - ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Range, RangeInclusive, Sub, SubAssign}, + ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, RangeInclusive, Sub, SubAssign}, }; #[derive(PartialEq, Eq, Clone, Copy, Debug)] @@ -416,7 +416,7 @@ #[inline] pub fn contains(&self, point: Point) -> bool { - self.x_range().contains(point.x) && self.y_range().contains(point.y) + self.x_range().contains(&point.x) && self.y_range().contains(&point.y) } #[inline] @@ -467,22 +467,6 @@ } } -trait RangeContains { - fn contains(&self, value: T) -> bool; -} - -impl RangeContains for Range { - fn contains(&self, value: T) -> bool { - value >= self.start && value < self.end - } -} - -impl RangeContains for RangeInclusive { - fn contains(&self, value: T) -> bool { - value >= *self.start() && value <= *self.end() - } -} - trait RangeClamp { fn clamp(&self, value: T) -> T; }