110class CCTWaterSurface : CCTBase
111{
112 protected const int HEIGHT_DIFF_LIMIT_METERS = 1.0;
113
114 protected float m_MaximalActionDistanceSq;
115 protected string m_SurfaceType; //!DEPRECATED
116 protected ref array<string> m_AllowedSurfaceList;
117
118 void CCTWaterSurface(float maximal_target_distance = UAMaxDistances.DEFAULT, string surfaceType = "")
119 {
120 m_MaximalActionDistanceSq = maximal_target_distance * maximal_target_distance;
121 m_SurfaceType = surfaceType;
122
123 m_AllowedSurfaceList = new array<string>();
124 surfaceType.Split("|", m_AllowedSurfaceList);
125 }
126
127 override bool Can(PlayerBase player, ActionTarget target)
128 {
129 if (!target || (target && target.GetObject()))
130 return false;
131
133 vector hitPosition = target.GetCursorHitPos();
134
135 string surfaceType;
136 float waterLevel = player.GetCurrentWaterLevel();
137 g_Game.SurfaceGetType3D(hitPosition[0], hitPosition[1] + waterLevel, hitPosition[2], surfaceType);
138
139 if (waterLevel > 0.0)
140 return Surface.AllowedWaterSurface(hitPosition[1] + waterLevel, surfaceType, m_AllowedSurfaceList);
141
142 float surfaceHeight = g_Game.SurfaceY(hitPosition[0], hitPosition[2]);
144 if (!surfaceType)
145 {
146 surfaceHeight = hitPosition[1];
147 }
148
149 float heightDiff = Math.AbsFloat(hitPosition[1] - surfaceHeight);
150 if (surfaceType != "" && heightDiff > HEIGHT_DIFF_LIMIT_METERS)
151 return false;
152
153 float distSq = vector.DistanceSq(player.GetPosition(), hitPosition);
154 if (distSq > m_MaximalActionDistanceSq)
155 return false;
156
157 return Surface.AllowedWaterSurface(hitPosition[1], surfaceType, m_AllowedSurfaceList);
158 }
159
160 override bool CanContinue(PlayerBase player, ActionTarget target)
161 {
162 return true;
163 }
164}
165
167class CCTWaterSurfaceEx : CCTBase
168{
169 protected float m_MaximalActionDistanceSq;
170 protected int m_AllowedLiquidSource;
171
172 void CCTWaterSurfaceEx(float maximal_target_distance, int allowedLiquidSource)
173 {
174 m_MaximalActionDistanceSq = maximal_target_distance * maximal_target_distance;
175 m_AllowedLiquidSource = allowedLiquidSource;
176 }
177
178 override bool Can(PlayerBase player, ActionTarget target)
179 {
180 if (!target || (target && target.GetObject()))
181 return false;
182
183 vector hitPosition = target.GetCursorHitPos();
184 string surfaceType;
185 g_Game.SurfaceGetType3D(hitPosition[0], hitPosition[1], hitPosition[2], surfaceType);
186
187 float distSq = vector.DistanceSq(player.GetPosition(), hitPosition);
188 if (distSq > m_MaximalActionDistanceSq)
189 return false;
190
191 if(surfaceType == "" && hitPosition[1] > g_Game.SurfaceGetSeaLevelMax())
192 return false;
193
194 return Surface.CheckLiquidSource(hitPosition[1], surfaceType, m_AllowedLiquidSource);
195 }
196
197 override bool CanContinue(PlayerBase player, ActionTarget target)
198 {
199 return true;
200 }
201}