File: AdanaxisPieceEffector.rb

package info (click to toggle)
adanaxisgpl 1.2.5.dfsg.1-6
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch
  • size: 39,988 kB
  • sloc: ansic: 69,023; cpp: 65,175; ruby: 14,217; xml: 8,416; sh: 7,434; perl: 2,233; objc: 256; makefile: 154; yacc: 92
file content (173 lines) | stat: -rw-r--r-- 5,050 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#%Header {
##############################################################################
#
# File data-adanaxis/ruby/AdanaxisPieceEffector.rb
#
# Copyright Andy Southgate 2006-2007
#
# This file may be used and distributed under the terms of the Mushware
# Software Licence version 1.4, under the terms for 'Proprietary original
# source files'.  If not supplied with this software, a copy of the licence
# can be obtained from Mushware Limited via http://www.mushware.com/.
# One of your options under that licence is to use and distribute this file
# under the terms of the GNU General Public Licence version 2.
#
# This software carries NO WARRANTY of any kind.
#
##############################################################################
#%Header } lORLU4vT56ruWJ92wVVyiw
# $Id: AdanaxisPieceEffector.rb,v 1.14 2007/06/27 13:18:54 southa Exp $
# $Log: AdanaxisPieceEffector.rb,v $
# Revision 1.14  2007/06/27 13:18:54  southa
# Debian packaging
#
# Revision 1.13  2007/06/27 12:58:11  southa
# Debian packaging
#
# Revision 1.12  2007/06/08 16:23:03  southa
# Level 26
#
# Revision 1.11  2007/06/06 12:24:13  southa
# Level 22
#
# Revision 1.10  2007/05/22 16:44:58  southa
# Level 18
#
# Revision 1.9  2007/05/22 12:59:08  southa
# Vortex effect on player
#
# Revision 1.8  2007/05/21 17:04:42  southa
# Player effectors
#
# Revision 1.7  2007/05/21 13:32:51  southa
# Flush weapon
#
# Revision 1.6  2007/04/18 09:21:53  southa
# Header and level fixes
#
# Revision 1.5  2007/04/16 08:41:06  southa
# Level and header mods
#
# Revision 1.4  2007/03/21 11:56:05  southa
# Rail effects and damage icons
#
# Revision 1.3  2007/03/13 21:45:08  southa
# Release process
#
# Revision 1.2  2006/11/14 20:28:36  southa
# Added rail gun
#
# Revision 1.1  2006/11/03 18:46:31  southa
# Damage effectors
#

class AdanaxisPieceEffector < AdanaxisPiece
  extend MushRegistered
  mushRegistered_install

  def initialize(inParams={})
    AdanaxisUtil.cSpellCheck(inParams)
    @m_defaultType = "e"
    super
    @m_owner = inParams[:owner] || ""
    @m_lifeMsec = inParams[:lifetime_msec] || 0
    @m_rail = inParams[:rail] || false
    @m_isFlush = inParams[:is_flush] || false

    if @m_isFlush
      @m_callInterval = 100
    else
      @m_callInterval = nil
    end

    return @m_callInterval
  end

  mush_accessor :m_rail, :m_owner

  def mDamageFactor(inPiece)
    if @m_rail
      retVal = @m_damageFactor
    else
      separation = (mPost.position - inPiece.mPost.position).mMagnitude
      factor = ((@m_hitPoints - separation) / @m_hitPoints).mClamp(0.0, 1.0)
      factor *= factor * factor # 4D so inverse cube law
      retVal = @m_damageFactor * factor
    end
    retVal
  end

  def mFlushEffect
    flarePost = mPost.dup

    flareOffset = MushTools.cRandomUnitVector * (5+rand(10))
    flareVel = flareOffset * -0.03

    flarePost.position = flarePost.position + flareOffset
    flarePost.velocity = flareVel

    $currentLogic.mEffects.mExploCreate(
      :post => flarePost,
      :explosion_lifetime_range => 600..600,
      :explosion_scale_range => 1.5..2.0,
      :alpha_stutter => 0
    )
  end

  def mActionTimer
    if @m_isFlush
      mLoad
      mFlushEffect
    end
    @m_callInterval
  end


  def mCollisionHandle(event)
    if @m_isFlush
      unless event.mPiece2.mOriginalHitPoints > 500.0 # Don't move heavy objects
        distVec = event.mPiece2.mPost.position - mPost.position
        dist = distVec.mMagnitude
        dist = 10 if dist < 10
        angScale = 0.01 / dist
        distNorm = distVec * (1/dist)
        angAccel = MushTools.cRotationInXWPlane(distNorm.x*angScale)
        MushTools.cRotationInZWPlane(distNorm.y*angScale).mRotate(angAccel)
        MushTools.cRotationInYZPlane(distNorm.z*angScale).mRotate(angAccel)
        MushTools.cRotationInXYPlane(distNorm.w*angScale).mRotate(angAccel)
        angAccel.mNormalise!

        vel = event.mPiece2.mPost.velocity
        event.mPiece2.mPost.velocity = vel - distNorm * (0.2/dist)
        angVel = event.mPiece2.mPost.angular_velocity
        angAccel.mRotate(angVel)
        event.mPiece2.mPost.angular_velocity = MushTools::cSlerp(angVel, MushRotation.new, 0.01)

        if event.mPiece2.kind_of?(AdanaxisPiecePlayer)
          # Different behaviour for player
          event.mPiece2.mControlReleasedSet(true)
        end
      end
    elsif @m_rail
      # Rail impact effect
      if event.mCollisionPoint
        $currentLogic.mEffects.mFlareCreate(
          :post => MushPost.new(:position => event.mCollisionPoint),
          :flare_lifetime_range => 400..500,
          :flare_scale_range => 8.0..9.0,
          :alpha_stutter => 0.5
        )
        $currentLogic.mEffects.mExplode(
          :post => MushPost.new(:position => event.mCollisionPoint),
          :effect_scale => 1.0,
          :embers => 10,
          :ember_speed_range => 0.1..0.2,
          :explosions => 0,
          :flares => 1,
          :flare_lifetime_range => 900..1000,
          :flare_scale_range => 2.0..2.1
        )
      end
    end
  end
end