MCPcopy Create free account
hub / github.com/OpenRCT2/OpenRCT2 / Create

Method Create

src/openrct2/entity/Duck.cpp:293–330  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

291 }
292
293 void Duck::Create(const CoordsXY& pos)
294 {
295 auto* duck = getGameState().entities.CreateEntity<Duck>();
296 if (duck == nullptr)
297 return;
298
299 CoordsXY targetPos = pos;
300
301 int32_t offsetXY = ScenarioRand() & 0x1E;
302 targetPos.x += offsetXY;
303 targetPos.y += offsetXY;
304
305 duck->spriteData.width = 9;
306 duck->spriteData.heightMin = 12;
307 duck->spriteData.heightMax = 9;
308 duck->target_x = targetPos.x;
309 duck->target_y = targetPos.y;
310 uint8_t direction = ScenarioRand() & 3;
311 switch (direction)
312 {
313 case 0:
314 targetPos.x = GetMapSizeMaxXY().x - (ScenarioRand() & 0x3F);
315 break;
316 case 1:
317 targetPos.y = ScenarioRand() & 0x3F;
318 break;
319 case 2:
320 targetPos.x = ScenarioRand() & 0x3F;
321 break;
322 case 3:
323 targetPos.y = GetMapSizeMaxXY().y - (ScenarioRand() & 0x3F);
324 break;
325 }
326 duck->orientation = direction << 3;
327 duck->moveTo({ targetPos.x, targetPos.y, 496 });
328 duck->state = DuckState::FlyToWater;
329 duck->frame = 0;
330 }
331
332 void Duck::Update()
333 {

Callers 1

Calls 3

ScenarioRandFunction · 0.85
GetMapSizeMaxXYFunction · 0.85
moveToMethod · 0.65

Tested by

no test coverage detected