Skip to content

Commit

Permalink
Addon: catapults attack allies
Browse files Browse the repository at this point in the history
# Conflicts:
#	libs/s25main/addons/const_addons.h
  • Loading branch information
kubaau committed Dec 13, 2024
1 parent 11cb7c0 commit b285d7e
Show file tree
Hide file tree
Showing 25 changed files with 64 additions and 4 deletions.
1 change: 1 addition & 0 deletions data/RTTR/campaigns/roman/MISS200.lua
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ function onSettingsReady()
checkVersion()
rttr:Log("-----------------------\n MISS200.lua loaded... \n-----------------------\n")
rttr:ResetAddons()
rttr:SetAddon(ADDON_CATAPULTS_ATTACK_ALLIES, true)
rttr:SetAddon(ADDON_FRONTIER_DISTANCE_REACHABLE, true)
rttr:SetGameSettings({
["fow"] = EXP_CLASSIC,
Expand Down
1 change: 1 addition & 0 deletions data/RTTR/campaigns/roman/MISS201.lua
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ function onSettingsReady()
checkVersion()
rttr:Log("-----------------------\n MISS201.lua loaded... \n-----------------------\n")
rttr:ResetAddons()
rttr:SetAddon(ADDON_CATAPULTS_ATTACK_ALLIES, true)
rttr:SetAddon(ADDON_FRONTIER_DISTANCE_REACHABLE, true)
rttr:SetGameSettings({
["fow"] = EXP_CLASSIC,
Expand Down
1 change: 1 addition & 0 deletions data/RTTR/campaigns/roman/MISS202.lua
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ function onSettingsReady()
checkVersion()
rttr:Log("-----------------------\n MISS202.lua loaded... \n-----------------------\n")
rttr:ResetAddons()
rttr:SetAddon(ADDON_CATAPULTS_ATTACK_ALLIES, true)
rttr:SetAddon(ADDON_FRONTIER_DISTANCE_REACHABLE, true)
rttr:SetGameSettings({
["fow"] = EXP_CLASSIC,
Expand Down
1 change: 1 addition & 0 deletions data/RTTR/campaigns/roman/MISS203.lua
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ function onSettingsReady()
checkVersion()
rttr:Log("-----------------------\n MISS203.lua loaded... \n-----------------------\n")
rttr:ResetAddons()
rttr:SetAddon(ADDON_CATAPULTS_ATTACK_ALLIES, true)
rttr:SetAddon(ADDON_FRONTIER_DISTANCE_REACHABLE, true)
rttr:SetGameSettings({
["fow"] = EXP_CLASSIC,
Expand Down
1 change: 1 addition & 0 deletions data/RTTR/campaigns/roman/MISS204.lua
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ function onSettingsReady()
checkVersion()
rttr:Log("-----------------------\n MISS204.lua loaded... \n-----------------------\n")
rttr:ResetAddons()
rttr:SetAddon(ADDON_CATAPULTS_ATTACK_ALLIES, true)
rttr:SetAddon(ADDON_FRONTIER_DISTANCE_REACHABLE, true)
rttr:SetGameSettings({
["fow"] = EXP_CLASSIC,
Expand Down
1 change: 1 addition & 0 deletions data/RTTR/campaigns/roman/MISS205.lua
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ function onSettingsReady()
checkVersion()
rttr:Log("-----------------------\n MISS205.lua loaded... \n-----------------------\n")
rttr:ResetAddons()
rttr:SetAddon(ADDON_CATAPULTS_ATTACK_ALLIES, true)
rttr:SetAddon(ADDON_FRONTIER_DISTANCE_REACHABLE, true)
rttr:SetGameSettings({
["fow"] = EXP_CLASSIC,
Expand Down
1 change: 1 addition & 0 deletions data/RTTR/campaigns/roman/MISS206.lua
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ function onSettingsReady()
checkVersion()
rttr:Log("-----------------------\n MISS206.lua loaded... \n-----------------------\n")
rttr:ResetAddons() -- S2-settings
rttr:SetAddon(ADDON_CATAPULTS_ATTACK_ALLIES, true)
rttr:SetAddon(ADDON_FRONTIER_DISTANCE_REACHABLE, true)
rttr:SetGameSettings({
["fow"] = EXP_CLASSIC,
Expand Down
1 change: 1 addition & 0 deletions data/RTTR/campaigns/roman/MISS207.lua
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ function onSettingsReady()
checkVersion()
rttr:Log("-----------------------\n MISS207.lua loaded... \n-----------------------\n")
rttr:ResetAddons()
rttr:SetAddon(ADDON_CATAPULTS_ATTACK_ALLIES, true)
rttr:SetAddon(ADDON_FRONTIER_DISTANCE_REACHABLE, true)
rttr:SetGameSettings({
["fow"] = EXP_CLASSIC,
Expand Down
1 change: 1 addition & 0 deletions data/RTTR/campaigns/roman/MISS208.lua
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ function onSettingsReady()
checkVersion()
rttr:Log("-----------------------\n MISS208.lua loaded... \n-----------------------\n")
rttr:ResetAddons()
rttr:SetAddon(ADDON_CATAPULTS_ATTACK_ALLIES, true)
rttr:SetAddon(ADDON_FRONTIER_DISTANCE_REACHABLE, true)
rttr:SetGameSettings({
["fow"] = EXP_CLASSIC,
Expand Down
1 change: 1 addition & 0 deletions data/RTTR/campaigns/roman/MISS209.lua
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ function onSettingsReady()
checkVersion()
rttr:Log("-----------------------\n MISS209.lua loaded... \n-----------------------\n")
rttr:ResetAddons()
rttr:SetAddon(ADDON_CATAPULTS_ATTACK_ALLIES, true)
rttr:SetAddon(ADDON_FRONTIER_DISTANCE_REACHABLE, true)
rttr:SetGameSettings({
["fow"] = EXP_CLASSIC,
Expand Down
1 change: 1 addition & 0 deletions data/RTTR/campaigns/world/AFRICA.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ end
function onSettingsReady()
rttr:Log("-----------------------\n AFRICA.lua loaded... \n-----------------------\n")
rttr:ResetAddons()
rttr:SetAddon(ADDON_CATAPULTS_ATTACK_ALLIES, true)
rttr:SetAddon(ADDON_FRONTIER_DISTANCE_REACHABLE, true)
rttr:SetGameSettings({
["fow"] = EXP_CLASSIC,
Expand Down
1 change: 1 addition & 0 deletions data/RTTR/campaigns/world/AUSTRA.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ end
function onSettingsReady()
rttr:Log("-----------------------\n AUSTRA.lua loaded... \n-----------------------\n")
rttr:ResetAddons()
rttr:SetAddon(ADDON_CATAPULTS_ATTACK_ALLIES, true)
rttr:SetAddon(ADDON_FRONTIER_DISTANCE_REACHABLE, true)
rttr:SetGameSettings({
["fow"] = EXP_CLASSIC,
Expand Down
1 change: 1 addition & 0 deletions data/RTTR/campaigns/world/EUROPE.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ end
function onSettingsReady()
rttr:Log("-----------------------\n EUROPE.lua loaded... \n-----------------------\n")
rttr:ResetAddons()
rttr:SetAddon(ADDON_CATAPULTS_ATTACK_ALLIES, true)
rttr:SetAddon(ADDON_FRONTIER_DISTANCE_REACHABLE, true)
rttr:SetGameSettings({
["fow"] = EXP_CLASSIC,
Expand Down
1 change: 1 addition & 0 deletions data/RTTR/campaigns/world/GREEN.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ end
function onSettingsReady()
rttr:Log("-----------------------\n GREEN.lua loaded... \n-----------------------\n")
rttr:ResetAddons()
rttr:SetAddon(ADDON_CATAPULTS_ATTACK_ALLIES, true)
rttr:SetAddon(ADDON_FRONTIER_DISTANCE_REACHABLE, true)
rttr:SetGameSettings({
["fow"] = EXP_CLASSIC,
Expand Down
1 change: 1 addition & 0 deletions data/RTTR/campaigns/world/JAPAN.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ end
function onSettingsReady()
rttr:Log("-----------------------\n JAPAN.lua loaded... \n-----------------------\n")
rttr:ResetAddons()
rttr:SetAddon(ADDON_CATAPULTS_ATTACK_ALLIES, true)
rttr:SetAddon(ADDON_FRONTIER_DISTANCE_REACHABLE, true)
rttr:SetGameSettings({
["fow"] = EXP_CLASSIC,
Expand Down
1 change: 1 addition & 0 deletions data/RTTR/campaigns/world/NAMERICA.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ end
function onSettingsReady()
rttr:Log("-----------------------\n NAMERICA.lua loaded... \n-----------------------\n")
rttr:ResetAddons()
rttr:SetAddon(ADDON_CATAPULTS_ATTACK_ALLIES, true)
rttr:SetAddon(ADDON_FRONTIER_DISTANCE_REACHABLE, true)
rttr:SetGameSettings({
["fow"] = EXP_CLASSIC,
Expand Down
1 change: 1 addition & 0 deletions data/RTTR/campaigns/world/NASIA.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ end
function onSettingsReady()
rttr:Log("-----------------------\n NASIA.lua loaded... \n-----------------------\n")
rttr:ResetAddons()
rttr:SetAddon(ADDON_CATAPULTS_ATTACK_ALLIES, true)
rttr:SetAddon(ADDON_FRONTIER_DISTANCE_REACHABLE, true)
rttr:SetGameSettings({
["fow"] = EXP_CLASSIC,
Expand Down
1 change: 1 addition & 0 deletions data/RTTR/campaigns/world/SAMERICA.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ end
function onSettingsReady()
rttr:Log("-----------------------\n SAMERICA.lua loaded... \n-----------------------\n")
rttr:ResetAddons()
rttr:SetAddon(ADDON_CATAPULTS_ATTACK_ALLIES, true)
rttr:SetAddon(ADDON_FRONTIER_DISTANCE_REACHABLE, true)
rttr:SetGameSettings({
["fow"] = EXP_CLASSIC,
Expand Down
1 change: 1 addition & 0 deletions data/RTTR/campaigns/world/SASIA.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ end
function onSettingsReady()
rttr:Log("-----------------------\n SASIA.lua loaded... \n-----------------------\n")
rttr:ResetAddons()
rttr:SetAddon(ADDON_CATAPULTS_ATTACK_ALLIES, true)
rttr:SetAddon(ADDON_FRONTIER_DISTANCE_REACHABLE, true)
rttr:SetGameSettings({
["fow"] = EXP_CLASSIC,
Expand Down
1 change: 1 addition & 0 deletions libs/s25main/GlobalGameSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ void GlobalGameSettings::registerAllAddons()
AddonBattlefieldPromotion,
AddonBurnDuration,
AddonCatapultGraphics,
AddonCatapultsAttackAllies,
AddonChangeGoldDeposits,
AddonCharburner,
AddonCoinsCapturedBld,
Expand Down
18 changes: 18 additions & 0 deletions libs/s25main/addons/AddonCatapultsAttackAllies.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (C) 2005 - 2021 Settlers Freaks (sf-team at siedler25.org)
//
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#include "AddonBool.h"
#include "mygettext/mygettext.h"

class AddonCatapultsAttackAllies : public AddonBool
{
public:
AddonCatapultsAttackAllies()
: AddonBool(AddonId::CATAPULTS_ATTACK_ALLIES, AddonGroup::Military, _("Catapults attack allies"),
_("Catapults will throw stones at allied buildings\n"
"(as they did in S2)"))
{}
};
1 change: 1 addition & 0 deletions libs/s25main/addons/Addons.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// Include with all addons

#include "addons/AddonCatapultGraphics.h"
#include "addons/AddonCatapultsAttackAllies.h"
#include "addons/AddonExhaustibleWater.h"
#include "addons/AddonInexhaustibleMines.h"
#include "addons/AddonLimitCatapults.h"
Expand Down
5 changes: 4 additions & 1 deletion libs/s25main/addons/const_addons.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
// 00E Jonathan
// 00F Jarno
// 010 aztimh
// 011 kubaau

// Do not forget to add your Addon to GlobalGameSettings::registerAllAddons @ GlobalGameSettings.cpp!
// Never use a number twice!
Expand Down Expand Up @@ -74,7 +75,9 @@ ENUM_WITH_STRING(AddonId, LIMIT_CATAPULTS = 0x00000000, INEXHAUSTIBLE_MINES = 0x

AUTOFLAGS = 0x00F00000,

WINE = 0x01000000)
WINE = 0x01000000,

CATAPULTS_ATTACK_ALLIES = 0x01100000)
//-V:AddonId:801

enum class AddonGroup : unsigned
Expand Down
22 changes: 19 additions & 3 deletions libs/s25main/figures/nofCatapultMan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
#include "CatapultStone.h"
#include "EventManager.h"
#include "GamePlayer.h"
#include "GlobalGameSettings.h"
#include "Loader.h"
#include "SerializedGameData.h"
#include "addons/AddonCatapultsAttackAllies.h"
#include "buildings/nobMilitary.h"
#include "buildings/nobUsual.h"
#include "enum_cast.hpp"
Expand Down Expand Up @@ -94,6 +96,22 @@ void nofCatapultMan::DrawWorking(DrawPoint drawPt)
}
}

bool nofCatapultMan::CanAttackBuilding(nobBaseMilitary* bld) const
{
// only proper military buildings - no HQ's etc.
if(bld->GetGOT() != GO_Type::NobMilitary)
return false;

if(bld->CanBeAttackedBy(player))
return true;

// anyone but ourselves
if(world->GetGGS().isEnabled(AddonId::CATAPULTS_ATTACK_ALLIES))
return bld->GetPlayer() != player;

return false;
}

void nofCatapultMan::HandleDerivedEvent(const unsigned /*id*/)
{
switch(state)
Expand All @@ -109,9 +127,7 @@ void nofCatapultMan::HandleDerivedEvent(const unsigned /*id*/)
sortedMilitaryBlds buildings = world->LookForMilitaryBuildings(pos, 3);
for(auto* building : buildings)
{
// Auch ein richtiges Militärgebäude (kein HQ usw.),
if(building->GetGOT() == GO_Type::NobMilitary
&& world->GetPlayer(player).CanAttack(building->GetPlayer()))
if(CanAttackBuilding(building))
{
// Was nicht im Nebel liegt und auch schon besetzt wurde (nicht neu gebaut)?
if(world->GetNode(building->GetPos()).fow[player].visibility == Visibility::Visible
Expand Down
2 changes: 2 additions & 0 deletions libs/s25main/figures/nofCatapultMan.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "nofBuildingWorker.h"
class SerializedGameData;
class nobBaseMilitary;
class nobUsual;

/// Arbeiter im Katapult
Expand Down Expand Up @@ -39,6 +40,7 @@ class nofCatapultMan : public nofBuildingWorker
void DrawWorking(DrawPoint drawPt) override;
/// Id in jobs.bob or carrier.bob when carrying a ware
unsigned short GetCarryID() const override { return 0; }
bool CanAttackBuilding(nobBaseMilitary* bld) const;

public:
nofCatapultMan(MapPoint pos, unsigned char player, nobUsual* workplace);
Expand Down

0 comments on commit b285d7e

Please sign in to comment.