[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Stratagus-CVS] stratagus/src/action action_repair.c
From: |
address@hidden |
Subject: |
[Stratagus-CVS] stratagus/src/action action_repair.c |
Date: |
13 Dec 2003 19:32:09 +1100 |
CVSROOT: /home/strat
Module name: stratagus
Changes by: <address@hidden> 03/12/13 19:32:09
Modified files:
src/action : action_repair.c
Log message:
Tabs, cleanup
Patches:
Index: stratagus/src/action/action_repair.c
diff -u stratagus/src/action/action_repair.c:1.61
stratagus/src/action/action_repair.c:1.62
--- stratagus/src/action/action_repair.c:1.61 Wed Dec 10 19:22:04 2003
+++ stratagus/src/action/action_repair.c Sat Dec 13 19:32:09 2003
@@ -3,14 +3,14 @@
// \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
// / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ |
// /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
-// \/ \/ \//_____/ \/
+// \/ \/ \//_____/ \/
// ______________________ ______________________
-// T H E W A R B E G I N S
-// Stratagus - A free fantasy real time strategy game engine
+// T H E W A R B E G I N S
+// Stratagus - A free fantasy real time strategy game engine
//
-/address@hidden action_repair.c - The repair action. */
+/address@hidden action_repair.c - The repair action. */
//
-// (c) Copyright 1999-2003 by Vladi Shabanski and Jimmy Salmon
+// (c) Copyright 1999-2004 by Vladi Shabanski and Jimmy Salmon
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@@ -26,12 +26,12 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: action_repair.c,v 1.61 2003/12/10 08:22:04 wizzard Exp $
+// $Id: action_repair.c,v 1.62 2003/12/13 08:32:09 wizzard Exp $
//@{
/*----------------------------------------------------------------------------
--- Includes
+-- Includes
----------------------------------------------------------------------------*/
#include <stdio.h>
@@ -50,250 +50,252 @@
#include "interface.h"
/*----------------------------------------------------------------------------
--- Functions
+-- Functions
----------------------------------------------------------------------------*/
/**
-** Generic unit repair.
+** Generic unit repair.
**
-** @param unit Unit, for that the repair animation is played.
-** @param repair Repair animation.
+** @param unit Unit, for that the repair animation is played.
+** @param repair Repair animation.
*/
local void DoActionRepairGeneric(Unit* unit, const Animation* repair)
{
- int flags;
+ int flags;
- flags = UnitShowAnimation(unit, repair);
+ flags = UnitShowAnimation(unit, repair);
- if ((flags & AnimationSound)) {
- PlayUnitSound(unit, VoiceRepairing);
- }
+ if ((flags & AnimationSound)) {
+ PlayUnitSound(unit, VoiceRepairing);
+ }
}
/**
-** Repair a unit.
+** Repair a unit.
**
-** @param unit unit repairing
-** @param goal unit being repaired
+** @param unit unit repairing
+** @param goal unit being repaired
**
*/
local void RepairUnit(Unit* unit, Unit* goal)
{
- Player* player;
- int i;
- int animlength;
- Animation* anim;
- int hp;
- char buf[100];
-
- player = unit->Player;
-
- if (goal->Orders[0].Action != UnitActionBuilded) {
- //
- // Calculate the repair costs.
- //
- DebugCheck(!goal->Stats->HitPoints);
-
- //
- // Check if enough resources are available
- //
- for (i = 1; i < MaxCosts; ++i) {
- if (player->Resources[i] < goal->Type->RepairCosts[i]) {
- snprintf(buf, 100, "We need more %s for repair!",
- DefaultResourceNames[i]);
- NotifyPlayer(player, NotifyYellow, unit->X, unit->Y, buf);
- if (player->AiEnabled) {
- // FIXME: call back to AI?
- RefsDecrease(goal);
- unit->Orders[0].Goal = NULL;
- unit->Orders[0].Action = UnitActionStill;
- unit->State = unit->SubAction = 0;
- if (unit->Selected) { // update display for new action
- SelectedUnitChanged();
- }
+ Player* player;
+ int i;
+ int animlength;
+ Animation* anim;
+ int hp;
+ char buf[100];
+
+ player = unit->Player;
+
+ if (goal->Orders[0].Action != UnitActionBuilded) {
+ //
+ // Calculate the repair costs.
+ //
+ DebugCheck(!goal->Stats->HitPoints);
+
+ //
+ // Check if enough resources are available
+ //
+ for (i = 1; i < MaxCosts; ++i) {
+ if (player->Resources[i] < goal->Type->RepairCosts[i]) {
+ snprintf(buf, 100, "We need more %s for
repair!",
+ DefaultResourceNames[i]);
+ NotifyPlayer(player, NotifyYellow, unit->X,
unit->Y, buf);
+ if (player->AiEnabled) {
+ // FIXME: call back to AI?
+ RefsDecrease(goal);
+ unit->Orders[0].Goal = NULL;
+ unit->Orders[0].Action =
UnitActionStill;
+ unit->State = unit->SubAction = 0;
+ if (unit->Selected) { //
update display for new action
+ SelectedUnitChanged();
+ }
+ }
+ // FIXME: We shouldn't animate if no resources
are available.
+ return;
+ }
+ }
+ //
+ // Subtract the resources
+ //
+ PlayerSubCosts(player, goal->Type->RepairCosts);
+ } else {
+ // hp is the current damage taken by the unit.
+ hp = (goal->Data.Builded.Progress * goal->Stats->HitPoints) /
+ (goal->Type->Stats->Costs[TimeCost] * 600) - goal->HP;
+ //
+ // Calculate the length of the attack (repair) anim.
+ //
+ animlength = 0;
+ for (anim = unit->Type->Animations->Repair; !(anim->Flags &
AnimationReset); ++anim) {
+ animlength += anim->Sleep;
}
- // FIXME: We shouldn't animate if no resources are available.
- return;
- }
- }
- //
- // Subtract the resources
- //
- PlayerSubCosts(player, goal->Type->RepairCosts);
- } else {
- // hp is the current damage taken by the unit.
- hp = (goal->Data.Builded.Progress * goal->Stats->HitPoints) /
- (goal->Type->Stats->Costs[TimeCost] * 600) - goal->HP;
- //
- // Calculate the length of the attack (repair) anim.
- //
- animlength = 0;
- for (anim = unit->Type->Animations->Repair; !(anim->Flags &
AnimationReset); ++anim) {
- animlength += anim->Sleep;
- }
- DebugLevel3("Repair animation is %d cycles long\n" _C_ animlength);
- // FIXME: implement this below:
- //unit->Data.Builded.Worker->Type->BuilderSpeedFactor;
- goal->Data.Builded.Progress += 100 * animlength * SpeedBuild;
- // Keep the same level of damage while increasing HP.
- goal->HP = (goal->Data.Builded.Progress * goal->Stats->HitPoints) /
- (goal->Type->Stats->Costs[TimeCost] * 600) - hp;
- if (goal->HP > goal->Stats->HitPoints) {
- goal->HP = goal->Stats->HitPoints;
+ DebugLevel3("Repair animation is %d cycles long\n" _C_
animlength);
+ // FIXME: implement this below:
+#if 0
+ unit->Data.Builded.Worker->Type->BuilderSpeedFactor;
+#endif
+ goal->Data.Builded.Progress += 100 * animlength * SpeedBuild;
+ // Keep the same level of damage while increasing HP.
+ goal->HP = (goal->Data.Builded.Progress *
goal->Stats->HitPoints) /
+ (goal->Type->Stats->Costs[TimeCost] * 600) - hp;
+ if (goal->HP > goal->Stats->HitPoints) {
+ goal->HP = goal->Stats->HitPoints;
+ }
}
- }
- if (CheckUnitToBeDrawn(goal)) {
- MustRedraw |= RedrawMinimap;
- }
- if (IsOnlySelected(goal)) { // Update panel if unit is
selected
- MustRedraw |= RedrawInfoPanel;
- }
+ if (CheckUnitToBeDrawn(goal)) {
+ MustRedraw |= RedrawMinimap;
+ }
+ if (IsOnlySelected(goal)) { // Update panel
if unit is selected
+ MustRedraw |= RedrawInfoPanel;
+ }
}
/**
** Animate unit repair
**
-** @param unit Unit, for that the repair animation is played.
+** @param unit Unit, for that the repair animation is played.
*/
local int AnimateActionRepair(Unit* unit)
{
- if (unit->Type->Animations) {
- DebugCheck(!unit->Type->Animations->Repair);
- DoActionRepairGeneric(unit, unit->Type->Animations->Repair);
- }
+ if (unit->Type->Animations) {
+ DebugCheck(!unit->Type->Animations->Repair);
+ DoActionRepairGeneric(unit, unit->Type->Animations->Repair);
+ }
- return 0;
+ return 0;
}
/**
-** Unit repairs
+** Unit repairs
**
-** @param unit Unit, for that the attack is handled.
+** @param unit Unit, for that the attack is handled.
*/
global void HandleActionRepair(Unit* unit)
{
- Unit* goal;
- int err;
+ Unit* goal;
+ int err;
- switch( unit->SubAction) {
- case 0:
- NewResetPath(unit);
- unit->SubAction = 1;
- // FALL THROUGH
- //
- // Move near to target.
- //
- case 1:
- // FIXME: RESET FIRST!! Why? We move first and than check if
- // something is in sight.
- err = DoActionMove(unit);
- if (unit->Reset) {
- //
- // No goal: if meeting damaged building repair it.
- //
- goal = unit->Orders[0].Goal;
-
- //
- // Target is dead, choose new one.
- //
- // Check if goal is correct unit.
- if (goal) {
- if (GoalGone(unit, goal)) {
- DebugLevel0Fn("repair target gone. Booohooo\n");
- unit->Orders[0].X = goal->X;
- unit->Orders[0].Y = goal->Y;
- RefsDecrease(goal);
- // FIXME: should I clear this here?
- unit->Orders[0].Goal = goal = NULL;
+ switch( unit->SubAction) {
+ case 0:
NewResetPath(unit);
- }
- } else if (unit->Player->AiEnabled) {
- // Ai players workers should stop if target is killed
- err = -1;
- }
-
+ unit->SubAction = 1;
+ // FALL THROUGH
//
- // Have reached target? FIXME: could use return value
+ // Move near to target.
//
- if (goal && MapDistanceBetweenUnits(unit, goal) <=
unit->Type->RepairRange &&
- goal->HP < goal->Type->Stats->HitPoints) {
- unit->State = 0;
- unit->SubAction = 2;
- unit->Reset = 1;
- UnitHeadingFromDeltaXY(unit,
- goal->X + (goal->Type->TileWidth - 1) / 2 - unit->X,
- goal->Y + (goal->Type->TileHeight - 1) / 2 - unit->Y);
- // FIXME: only if heading changes
- CheckUnitToBeDrawn(unit);
- } else if (err < 0) {
- if (goal) { // release reference
- RefsDecrease(goal);
- unit->Orders[0].Goal = NoUnitP;
- }
- unit->Orders[0].Action = UnitActionStill;
- unit->State = unit->SubAction = 0;
- if (unit->Selected) { // update display for new action
- SelectedUnitChanged();
- }
- return;
- }
-
- // FIXME: Should be it already?
- DebugCheck(unit->Orders[0].Action != UnitActionRepair);
- }
- break;
-
- //
- // Repair the target.
- //
- case 2:
- AnimateActionRepair(unit);
- if (unit->Reset) {
- goal = unit->Orders[0].Goal;
-
- //
- // Target is dead, choose new one.
- //
- // Check if goal is correct unit.
- // FIXME: should I do a function for this?
- if (goal) {
- if (GoalGone(unit, goal)) {
- DebugLevel0Fn("repair goal is gone\n");
- unit->Orders[0].X = goal->X;
- unit->Orders[0].Y = goal->Y;
- RefsDecrease(goal);
- // FIXME: should I clear this here?
- unit->Orders[0].Goal = goal = NULL;
- NewResetPath(unit);
- }
- }
- if (goal) {
- RepairUnit(unit, goal);
- goal = unit->Orders[0].Goal;
- }
+ case 1:
+ // FIXME: RESET FIRST!! Why? We move first and than
check if
+ // something is in sight.
+ err = DoActionMove(unit);
+ if (unit->Reset) {
+ //
+ // No goal: if meeting damaged building repair
it.
+ //
+ goal = unit->Orders[0].Goal;
+
+ //
+ // Target is dead, choose new one.
+ //
+ // Check if goal is correct unit.
+ if (goal) {
+ if (GoalGone(unit, goal)) {
+ DebugLevel0Fn("repair target
gone. Booohooo\n");
+ unit->Orders[0].X = goal->X;
+ unit->Orders[0].Y = goal->Y;
+ RefsDecrease(goal);
+ // FIXME: should I clear this
here?
+ unit->Orders[0].Goal = goal =
NULL;
+ NewResetPath(unit);
+ }
+ } else if (unit->Player->AiEnabled) {
+ // Ai players workers should stop if
target is killed
+ err = -1;
+ }
+
+ //
+ // Have reached target? FIXME: could use return
value
+ //
+ if (goal && MapDistanceBetweenUnits(unit, goal)
<= unit->Type->RepairRange &&
+ goal->HP <
goal->Type->Stats->HitPoints) {
+ unit->State = 0;
+ unit->SubAction = 2;
+ unit->Reset = 1;
+ UnitHeadingFromDeltaXY(unit,
+ goal->X +
(goal->Type->TileWidth - 1) / 2 - unit->X,
+ goal->Y +
(goal->Type->TileHeight - 1) / 2 - unit->Y);
+ // FIXME: only if heading changes
+ CheckUnitToBeDrawn(unit);
+ } else if (err < 0) {
+ if (goal) {
// release reference
+ RefsDecrease(goal);
+ unit->Orders[0].Goal = NoUnitP;
+ }
+ unit->Orders[0].Action =
UnitActionStill;
+ unit->State = unit->SubAction = 0;
+ if (unit->Selected) { //
update display for new action
+ SelectedUnitChanged();
+ }
+ return;
+ }
+
+ // FIXME: Should be it already?
+ DebugCheck(unit->Orders[0].Action !=
UnitActionRepair);
+ }
+ break;
//
- // Target is fine, choose new one.
+ // Repair the target.
//
- if (!goal || goal->HP >= goal->Stats->HitPoints) {
- if (goal) { // release reference
- RefsDecrease(goal);
- unit->Orders[0].Goal = NULL;
- }
- unit->Orders[0].Action = UnitActionStill;
- unit->SubAction = unit->State = 0;
- if (unit->Selected) { // update display for new action
- SelectedUnitChanged();
- }
- return;
- }
-
- // FIXME: automatic repair
- }
- break;
- }
+ case 2:
+ AnimateActionRepair(unit);
+ if (unit->Reset) {
+ goal = unit->Orders[0].Goal;
+
+ //
+ // Target is dead, choose new one.
+ //
+ // Check if goal is correct unit.
+ // FIXME: should I do a function for this?
+ if (goal) {
+ if (GoalGone(unit, goal)) {
+ DebugLevel0Fn("repair goal is
gone\n");
+ unit->Orders[0].X = goal->X;
+ unit->Orders[0].Y = goal->Y;
+ RefsDecrease(goal);
+ // FIXME: should I clear this
here?
+ unit->Orders[0].Goal = goal =
NULL;
+ NewResetPath(unit);
+ }
+ }
+ if (goal) {
+ RepairUnit(unit, goal);
+ goal = unit->Orders[0].Goal;
+ }
+
+ //
+ // Target is fine, choose new one.
+ //
+ if (!goal || goal->HP >=
goal->Stats->HitPoints) {
+ if (goal) {
// release reference
+ RefsDecrease(goal);
+ unit->Orders[0].Goal = NULL;
+ }
+ unit->Orders[0].Action =
UnitActionStill;
+ unit->SubAction = unit->State = 0;
+ if (unit->Selected) { //
update display for new action
+ SelectedUnitChanged();
+ }
+ return;
+ }
+
+ // FIXME: automatic repair
+ }
+ break;
+ }
}
//@}
- [Stratagus-CVS] stratagus/src/action action_repair.c,
address@hidden <=