[Wesnoth-commits] r10218 - in /trunk/src: actions.cpp ai.cpp playturn.cpp replay.cpp (February 20, 2006 - 15:45)

Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Headers

 

Author: xan
Date: Mon Feb 20 15:44:34 2006
New Revision: 10218

URL: http://svn.gna.org/viewcvs/wesnoth?rev=10218&view=rev
Log:
[special_filter] now works with 'attack' event.

Modified:
    trunk/src/actions.cpp
    trunk/src/ai.cpp
    trunk/src/playturn.cpp
    trunk/src/replay.cpp

Modified: trunk/src/actions.cpp
URL: http://svn.gna.org/viewcvs/wesnoth/trunk/src/actions.cpp?rev=10218&r1=10217&r2=10218&view=diff
==============================================================================
--- trunk/src/actions.cpp (original)
+++ trunk/src/actions.cpp Mon Feb 20 15:44:34 2006
@@ -719,7 +719,30 @@
                                                    units, state);
 
 	statistics::attack_context attack_stats(a->second,d->second,stats);
-
+	
+	LOG_NG << "firing attack event\n";
+	config dat;
+	dat.add_child("first");
+	dat.add_child("second");
+	(*(dat.child("first")))["weapon"]=a->second.attacks()[attack_with].name();
+	(*(dat.child("second")))["weapon"]=stats.defend_with != -1 ? d->second.attacks()[stats.defend_with].name() : "none";
+	gamemap::TERRAIN att_terrain = map[attacker.x][attacker.y];
+	std::string terrain_letter("");
+	terrain_letter += att_terrain;
+	(*(dat.child("first")))["terrain"]=terrain_letter;
+	gamemap::TERRAIN dtt_terrain = map[defender.x][defender.y];
+	terrain_letter = "";
+	terrain_letter += dtt_terrain;
+	(*(dat.child("second")))["terrain"]=terrain_letter;
+	game_events::fire("attack",attacker,defender,dat);
+	//the event could have killed either the attacker or
+	//defender, so we have to make sure they still exist
+	a = units.find(attacker);
+	d = units.find(defender);
+	if(a == units.end() || d == units.end() || size_t(attack_with) >= a->second.attacks().size() || size_t(stats.defend_with) >= d->second.attacks().size()) {
+		return;
+	}
+	
 	int orig_attacks = stats.nattacks;
 	int orig_defends = stats.ndefends;
 
@@ -802,7 +825,7 @@
 				game_events::fire("attacker_hits",attacker,defender,dat);
 				a = units.find(attacker);
 				d = units.find(defender);
-				if(a == units.end() || d == units.end()) {
+				if(a == units.end() || d == units.end() || size_t(attack_with) >= a->second.attacks().size() || size_t(stats.defend_with) >= d->second.attacks().size()) {
 					recalculate_fog(map,state,info,units,teams,attacker_side-1);
 					recalculate_fog(map,state,info,units,teams,defender_side-1);
 					gui.recalculate_minimap();
@@ -833,7 +856,7 @@
 				game_events::fire("attacker_misses",attacker,defender,dat);
 				a = units.find(attacker);
 				d = units.find(defender);
-				if(a == units.end() || d == units.end()) {
+				if(a == units.end() || d == units.end() || size_t(attack_with) >= a->second.attacks().size() || size_t(stats.defend_with) >= d->second.attacks().size()) {
 					recalculate_fog(map,state,info,units,teams,attacker_side-1);
 					recalculate_fog(map,state,info,units,teams,defender_side-1);
 					gui.recalculate_minimap();
@@ -1048,7 +1071,7 @@
 				game_events::fire("defender_hits",attacker,defender,dat);
 				a = units.find(attacker);
 				d = units.find(defender);
-				if(a == units.end() || d == units.end()) {
+				if(a == units.end() || d == units.end() || size_t(attack_with) >= a->second.attacks().size() || size_t(stats.defend_with) >= d->second.attacks().size()) {
 					recalculate_fog(map,state,info,units,teams,attacker_side-1);
 					recalculate_fog(map,state,info,units,teams,defender_side-1);
 					gui.recalculate_minimap();
@@ -1077,7 +1100,7 @@
 				game_events::fire("defender_misses",attacker,defender,dat);
 				a = units.find(attacker);
 				d = units.find(defender);
-				if(a == units.end() || d == units.end()) {
+				if(a == units.end() || d == units.end() || size_t(attack_with) >= a->second.attacks().size() || size_t(stats.defend_with) >= d->second.attacks().size()) {
 					recalculate_fog(map,state,info,units,teams,attacker_side-1);
 					recalculate_fog(map,state,info,units,teams,defender_side-1);
 					gui.recalculate_minimap();

Modified: trunk/src/ai.cpp
URL: http://svn.gna.org/viewcvs/wesnoth/trunk/src/ai.cpp?rev=10218&r1=10217&r2=10218&view=diff
==============================================================================
--- trunk/src/ai.cpp (original)
+++ trunk/src/ai.cpp Mon Feb 20 15:44:34 2006
@@ -1008,7 +1008,6 @@
 		}
 
 		recorder.add_attack(u,target,weapon);
-		game_events::fire("attack",u,target);
 
 		attack(info_.disp, info_.map, info_.teams, u, target, weapon, info_.units, info_.state, info_.gameinfo);
 		check_victory(info_.units,info_.teams);

Modified: trunk/src/playturn.cpp
URL: http://svn.gna.org/viewcvs/wesnoth/trunk/src/playturn.cpp?rev=10218&r1=10217&r2=10218&view=diff
==============================================================================
--- trunk/src/playturn.cpp (original)
+++ trunk/src/playturn.cpp Mon Feb 20 15:44:34 2006
@@ -756,17 +756,6 @@
 		current_paths_ = paths();
 		gui_.unhighlight_reach();
 
-		game_events::fire("attack",attacker_loc,defender_loc);
-
-		//the event could have killed either the attacker or
-		//defender, so we have to make sure they still exist
-		attacker = units_.find(attacker_loc);
-		defender = units_.find(defender_loc);
-
-		if(attacker == units_.end() || defender == units_.end() || size_t(weapons[res]) >= attacks.size()) {
-			return true;
-		}
-
 		gui_.invalidate_all();
 		gui_.draw();
 

Modified: trunk/src/replay.cpp
URL: http://svn.gna.org/viewcvs/wesnoth/trunk/src/replay.cpp?rev=10218&r1=10217&r2=10218&view=diff
==============================================================================
--- trunk/src/replay.cpp (original)
+++ trunk/src/replay.cpp Mon Feb 20 15:44:34 2006
@@ -898,14 +898,7 @@
 				if (!game_config::ignore_replay_errors) throw replay::error();
 			}
 
-			game_events::fire("attack",src,dst);
-
-			u = units.find(src);
-			tgt = units.find(dst);
-
-			if(u != units.end() && tgt != units.end()) {
-				attack(disp, map, teams, src, dst, weapon_num, units, state, gameinfo);
-			}
+			attack(disp, map, teams, src, dst, weapon_num, units, state, gameinfo);
 
 			u = units.find(src);
 			tgt = units.find(dst);



Related Mails




Powered by MHonArc, Updated Mon Feb 20 18:20:28 2006