Implemented Crab AI. Release Build 11683.

master
sigonasr2 2 months ago
parent 94de6bb10e
commit 3684e0f211
  1. 67
      Adventures in Lestoria/Crab.cpp
  2. 2
      Adventures in Lestoria/Version.h
  3. 18
      Adventures in Lestoria/assets/Campaigns/3_1.tmx
  4. 15
      Adventures in Lestoria/assets/config/MonsterStrategies.txt
  5. 1
      Adventures in Lestoria/assets/config/Monsters.txt
  6. BIN
      Adventures in Lestoria/assets/gamepack.pak
  7. 2
      Adventures in Lestoria/assets/maps/Monster_Presets.tmx
  8. BIN
      x64/Release/Adventures in Lestoria.exe

@ -47,5 +47,72 @@ using A=Attribute;
INCLUDE_game INCLUDE_game
void Monster::STRATEGY::CRAB(Monster&m,float fElapsedTime,std::string strategy){ void Monster::STRATEGY::CRAB(Monster&m,float fElapsedTime,std::string strategy){
enum PhaseName{
INIT,
MOVE,
PREPARE_CHARGE,
CHARGE,
};
switch(PHASE()){
case INIT:{
m.B(A::RANDOM_DIRECTION)=util::random()%2;
m.F(A::RANDOM_RANGE)=util::random_range(ConfigPixelsArr("Random Direction Range",0),ConfigPixelsArr("Random Direction Range",1));
SETPHASE(MOVE);
}break;
case MOVE:{
m.F(A::ATTACK_COOLDOWN)+=fElapsedTime;
m.F(A::LAST_JUMP_TIMER)+=fElapsedTime;
float distToPlayer=m.GetDistanceFrom(game->GetPlayer()->GetPos());
const bool outsideMaxShootingRange=distToPlayer>=ConfigPixelsArr("Stand Still and Shoot Range",1);
if(m.F(A::LAST_JUMP_TIMER)>=ConfigFloat("Stop Check Interval")){
if(util::random(100)<=ConfigFloat("Stop Percent")){
SETPHASE(PREPARE_CHARGE);
m.PerformAnimation("CHARGEUP",m.GetFacingDirectionToTarget(game->GetPlayer()->GetPos()));
m.F(A::CASTING_TIMER)=ConfigFloat("Charge Wait Time");
m.target=game->GetPlayer()->GetPos()+util::distance(m.GetPos(),game->GetPlayer()->GetPos())*util::pointTo(m.GetPos(),game->GetPlayer()->GetPos());
}else
if(util::random(100)<=ConfigFloat("Change Direction Chance"))m.B(A::RANDOM_DIRECTION)=!m.B(A::RANDOM_DIRECTION);
m.F(A::LAST_JUMP_TIMER)=0.f;
}else
if(outsideMaxShootingRange){
m.target=game->GetPlayer()->GetPos();
RUN_TOWARDS(m,fElapsedTime,"Run Towards");
}else
if(distToPlayer<ConfigPixels("Run Away Range")){
m.target=geom2d::line<float>(m.GetPos(),game->GetPlayer()->GetPos()).upoint(-1);
RUN_TOWARDS(m,fElapsedTime,"Run Towards");
}else
if(distToPlayer>=ConfigPixelsArr("Random Direction Range",0)&&distToPlayer<ConfigPixelsArr("Random Direction Range",1)){
#define CW true
#define CCW false
//We are going to walk in a circular direction either CW or CCW (determined in windup phase)
float dirFromPlayer=util::angleTo(game->GetPlayer()->GetPos(),m.GetPos());
float targetDir=m.B(A::RANDOM_DIRECTION)==CW?dirFromPlayer+PI/4:dirFromPlayer-PI/4;
m.target=game->GetPlayer()->GetPos()+vf2d{m.F(A::RANDOM_RANGE),targetDir}.cart();
RUN_TOWARDS(m,fElapsedTime,"Run Towards");
m.F(A::CHASE_TIMER)=1.f;
}
}break;
case PREPARE_CHARGE:{
m.F(A::CASTING_TIMER)-=fElapsedTime;
if(m.F(A::CASTING_TIMER)<=0.f){
SETPHASE(CHARGE);
m.F(A::CHASE_TIMER)=ConfigFloat("Charge Max Time");
m.PerformAnimation("PINCER");
}
}break;
case CHARGE:{
m.F(A::CHASE_TIMER)-=fElapsedTime;
RUN_TOWARDS(m,fElapsedTime,"Run Towards");
if(m.F(A::CHASE_TIMER)<=0.f||m.ReachedTargetPos()){
SETPHASE(MOVE);
m.B(A::RANDOM_DIRECTION)=util::random()%2;
m.F(A::RANDOM_RANGE)=util::random_range(ConfigPixelsArr("Random Direction Range",0),ConfigPixelsArr("Random Direction Range",1));
}
}break;
}
} }

@ -39,7 +39,7 @@ All rights reserved.
#define VERSION_MAJOR 1 #define VERSION_MAJOR 1
#define VERSION_MINOR 3 #define VERSION_MINOR 3
#define VERSION_PATCH 0 #define VERSION_PATCH 0
#define VERSION_BUILD 11674 #define VERSION_BUILD 11683
#define stringify(a) stringify_(a) #define stringify(a) stringify_(a)
#define stringify_(a) #a #define stringify_(a) #a

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<map version="1.10" tiledversion="1.10.2" class="Map" orientation="orthogonal" renderorder="right-down" width="335" height="165" tilewidth="24" tileheight="24" infinite="0" nextlayerid="8" nextobjectid="85"> <map version="1.10" tiledversion="1.10.2" class="Map" orientation="orthogonal" renderorder="right-down" width="335" height="165" tilewidth="24" tileheight="24" infinite="0" nextlayerid="8" nextobjectid="100">
<properties> <properties>
<property name="Background Music" propertytype="BGM" value="beach"/> <property name="Background Music" propertytype="BGM" value="beach"/>
<property name="Level Type" type="int" propertytype="LevelType" value="0"/> <property name="Level Type" type="int" propertytype="LevelType" value="0"/>
@ -1243,27 +1243,17 @@
</properties> </properties>
<point/> <point/>
</object> </object>
<object id="80" template="../maps/Monsters/Seagull.tx" x="558" y="1494"> <object id="97" template="../maps/Monsters/Crab.tx" x="576" y="1458">
<properties> <properties>
<property name="spawner" type="object" value="8"/> <property name="spawner" type="object" value="8"/>
</properties> </properties>
</object> </object>
<object id="81" template="../maps/Monsters/Seagull.tx" x="894" y="1338"> <object id="98" template="../maps/Monsters/Crab.tx" x="588" y="1422">
<properties> <properties>
<property name="spawner" type="object" value="8"/> <property name="spawner" type="object" value="8"/>
</properties> </properties>
</object> </object>
<object id="82" template="../maps/Monsters/Seagull.tx" x="948" y="1464"> <object id="99" template="../maps/Monsters/Crab.tx" x="588" y="1398">
<properties>
<property name="spawner" type="object" value="8"/>
</properties>
</object>
<object id="83" template="../maps/Monsters/Seagull.tx" x="864" y="1584">
<properties>
<property name="spawner" type="object" value="8"/>
</properties>
</object>
<object id="84" template="../maps/Monsters/Seagull.tx" x="978" y="1584">
<properties> <properties>
<property name="spawner" type="object" value="8"/> <property name="spawner" type="object" value="8"/>
</properties> </properties>

@ -1156,6 +1156,21 @@ MonsterStrategy
} }
Crab Crab
{ {
# When the monster will attempt to run away from target.
Run Away Range = 400
# Chooses a random direction within the confines of this range, stays within it.
Random Direction Range = 400,600
# Does not move and shoots from anywhere in these ranges.
Stand Still and Shoot Range = 600,600
# Anything outside the max "Stand Still and Shoot Range" will cause the monster to move towards the target instead.
# How often to check for a charge stop.
Stop Check Interval = 1s
# Percentage chance to perform charge each stop.
Stop Percent = 20%
Change Direction Chance = 10%
Charge Wait Time = 0.3s
Charge Max Time = 3s
} }
} }

@ -1537,6 +1537,7 @@ Monsters
WALK = 2, 0.15, Repeat WALK = 2, 0.15, Repeat
PINCER = 3, 0.3, Repeat PINCER = 3, 0.3, Repeat
DEATH = 2, 0.15, OneShot DEATH = 2, 0.15, OneShot
CHARGEUP = 1, 0.1, OneShot
} }
# Drop Item Name, Drop Percentage(0-100%), Drop Min Quantity, Drop Max Quantity # Drop Item Name, Drop Percentage(0-100%), Drop Min Quantity, Drop Max Quantity

@ -32,7 +32,7 @@
<object id="34" template="Monsters/Crab.tx" type="Monster" x="-120" y="408" width="28.8" height="28.8"/> <object id="34" template="Monsters/Crab.tx" type="Monster" x="-120" y="408" width="28.8" height="28.8"/>
<object id="36" template="Monsters/Pirate.tx" type="Monster" x="-24" y="420"/> <object id="36" template="Monsters/Pirate.tx" type="Monster" x="-24" y="420"/>
<object id="37" template="Monsters/Pirate Captain.tx" type="Monster" x="60" y="420"/> <object id="37" template="Monsters/Pirate Captain.tx" type="Monster" x="60" y="420"/>
<object id="38" name="Seagull" type="Monster" gid="26" x="18" y="498" width="38.4" height="38.4"/> <object id="38" template="Monsters/Seagull.tx" type="Monster" x="18" y="498"/>
<object id="39" template="Monsters/Pirate Buccaneer.tx" type="Monster" x="90" y="486"/> <object id="39" template="Monsters/Pirate Buccaneer.tx" type="Monster" x="90" y="486"/>
<object id="40" template="Monsters/Pirate Marauder.tx" type="Monster" x="-72" y="492"/> <object id="40" template="Monsters/Pirate Marauder.tx" type="Monster" x="-72" y="492"/>
<object id="41" template="Monsters/Sandworm.tx" type="Monster" x="168" y="534"/> <object id="41" template="Monsters/Sandworm.tx" type="Monster" x="168" y="534"/>

Loading…
Cancel
Save